AcmeUtils { public static void writeToPem(byte[] encoded, PemLabel label, Writer out) throws IOException { out.append("-----BEGIN ").append(label.toString()).append("-----\n"); out.append(new String(PEM_ENCODER.encode(encoded), StandardCharsets.US_ASCII)); out.append("\n-----END ").append(label.toString()).append("-----\n"); } private  AcmeUtils(); static byte[] sha256hash(String z); static String hexEncode(byte[] data); static String base64UrlEncode(byte[] data); static byte[] base64UrlDecode(String base64); static boolean isValidBase64Url(@Nullable String base64); static String toAce(String domain); static Instant parseTimestamp(String str); @Nullable static String stripErrorPrefix(@Nullable String type); static void writeToPem(byte[] encoded, PemLabel label, Writer out); @Nullable static String getContentType(@Nullable String header); static void validateContact(URI contact);  }
@Test public void testWriteToPem() throws IOException, CertificateEncodingException { List<X509Certificate> certChain = TestUtils.createCertificate(); ByteArrayOutputStream pemFile = new ByteArrayOutputStream(); try (Writer w = new OutputStreamWriter(pemFile)) { for (X509Certificate cert : certChain) { AcmeUtils.writeToPem(cert.getEncoded(), AcmeUtils.PemLabel.CERTIFICATE, w); } } ByteArrayOutputStream originalFile = new ByteArrayOutputStream(); try (InputStream in = getClass().getResourceAsStream("/cert.pem")) { byte[] buffer = new byte[2048]; int len; while ((len = in.read(buffer)) >= 0) { originalFile.write(buffer, 0, len); } } assertThat(pemFile.toByteArray(), is(originalFile.toByteArray())); }