class Crypto {

    public static X509Certificate[] loadX509Certificates(final String certsFile) throws CryptoException {

        File certFile = new File(certsFile);

        try (InputStream certStream  = new FileInputStream(certFile)) {

            final CertificateFactory cf = CertificateFactory.getInstance("X.509");
            List<? extends Certificate> certs = (List<? extends Certificate>) cf.generateCertificates(certStream);
            if (certs.isEmpty()) {
                throw new CryptoException("Certificate file contains empty certificate or an invalid certificate.");
            }
            return certs.toArray(new X509Certificate[certs.size()]);
        } catch (IOException ex) {
            LOG.error("loadX509Certificates: unable to process file: " + certFile.getAbsolutePath());
            throw new CryptoException(ex);
        } catch (CertificateException ex) {
            LOG.error("Unable to load certificates", ex);
            throw new CryptoException(ex);
        }
    }

}