static List<byte[]> readCertificates(Path path) throws CertificateException {
        final byte[] bytes;
        try {
            bytes = Files.readAllBytes(path);
        } catch (IOException e) {
            throw new CertificateException("Couldn't read certificates from file: " + path, e);
        }

        final String content = new String(bytes, StandardCharsets.US_ASCII);
        final Matcher m = CERT_PATTERN.matcher(content);

        final List<byte[]> certs = new ArrayList<>();
        int start = 0;
        while (m.find(start)) {
            final String s = m.group(1);
            byte[] der = Base64.getDecoder().decode(CharMatcher.breakingWhitespace().removeFrom(s));
            certs.add(der);

            start = m.end();
        }

        if (certs.isEmpty()) {
            throw new CertificateException("No certificates found in file: " + path);
        }

        return certs;
    }
@Test(expected = CertificateException.class)
    public void readCertificatesFailsOnInvalidFile() throws Exception {
        final File file = temporaryFolder.newFile();
        PemReader.readCertificates(file.toPath());
    }