public static Collection<X509Certificate> parseCertificates(String pemRepresentation) throws IOException,
            CertificateException {

        // The parser is very picky. We should trim each line of the input string.
        final String pem = pemRepresentation //
                .replaceAll("(?m) +$", "") // remove trailing whitespace
                .replaceAll("(?m)^ +", ""); // remove leading whitespace

        ByteArrayInputStream input = new ByteArrayInputStream(pem.getBytes(StandardCharsets.UTF_8));
        return parseCertificates(input);
    }
@Test
    public void testParseFullChain() throws Exception
    {
        // Setup fixture.
        try ( final InputStream stream = getClass().getResourceAsStream( "/fullchain.pem" ) )
        {
            // Execute system under test.
            final Collection<X509Certificate> result = CertificateManager.parseCertificates( stream );

            // Verify result.
            assertNotNull( result );
            assertEquals( 2, result.size() );
        }
    }