Package com.unboundid.util.ssl.cert
Class X509PEMFileReader
java.lang.Object
com.unboundid.util.ssl.cert.X509PEMFileReader
- All Implemented Interfaces:
Closeable,AutoCloseable
@ThreadSafety(level=NOT_THREADSAFE)
public final class X509PEMFileReader
extends Object
implements Closeable
This class provides a mechanism for reading PEM-encoded X.509 certificates
from a specified file. The PEM file may contain zero or more certificates.
Each certificate should consist of the following:
Any spaces that appear at the beginning or end of each line will be ignored. Empty lines and lines that start with the octothorpe (#) character will also be ignored.
- A line containing only the string "-----BEGIN CERTIFICATE-----".
- One or more lines representing the base64-encoded representation of the bytes that comprise the X.509 certificate.
- A line containing only the string "-----END CERTIFICATE-----".
Any spaces that appear at the beginning or end of each line will be ignored. Empty lines and lines that start with the octothorpe (#) character will also be ignored.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe header string that should appear on a line by itself before the base64-encoded representation of the bytes that comprise an X.509 certificate.static final StringThe footer string that should appear on a line by itself after the base64-encoded representation of the bytes that comprise an X.509 certificate. -
Constructor Summary
ConstructorsConstructorDescriptionX509PEMFileReader(File pemFile) Creates a new X.509 PEM file reader that will read certificate information from the specified file.X509PEMFileReader(InputStream inputStream) Creates a new X.509 PEM file reader that will read certificate information from the provided input stream.X509PEMFileReader(String pemFilePath) Creates a new X.509 PEM file reader that will read certificate information from the specified file. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this X.509 PEM file reader.Reads the next certificate from the PEM file.
-
Field Details
-
BEGIN_CERTIFICATE_HEADER
The header string that should appear on a line by itself before the base64-encoded representation of the bytes that comprise an X.509 certificate.- See Also:
-
END_CERTIFICATE_FOOTER
The footer string that should appear on a line by itself after the base64-encoded representation of the bytes that comprise an X.509 certificate.- See Also:
-
-
Constructor Details
-
X509PEMFileReader
Creates a new X.509 PEM file reader that will read certificate information from the specified file.- Parameters:
pemFilePath- The path to the PEM file from which the certificates should be read. This must not benulland the file must exist.- Throws:
IOException- If a problem occurs while attempting to open the file for reading.
-
X509PEMFileReader
Creates a new X.509 PEM file reader that will read certificate information from the specified file.- Parameters:
pemFile- The PEM file from which the certificates should be read. This must not benulland the file must exist.- Throws:
IOException- If a problem occurs while attempting to open the file for reading.
-
X509PEMFileReader
Creates a new X.509 PEM file reader that will read certificate information from the provided input stream.- Parameters:
inputStream- The input stream from which the certificates should be read. This must not benulland it must be open for reading.
-
-
Method Details
-
readCertificate
Reads the next certificate from the PEM file.- Returns:
- The certificate that was read, or
nullif the end of the file has been reached. - Throws:
IOException- If a problem occurs while trying to read data from the PEM file.CertException- If a problem occurs while trying to interpret data read from the PEM file as an X.509 certificate.
-
close
Closes this X.509 PEM file reader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- If a problem is encountered while attempting to close the reader.
-