Package com.unboundid.util.ssl.cert
Class X509PEMFileReader
- java.lang.Object
-
- com.unboundid.util.ssl.cert.X509PEMFileReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
@ThreadSafety(level=NOT_THREADSAFE) public final class X509PEMFileReader extends java.lang.Object implements java.io.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:- 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
Fields Modifier and Type Field Description static java.lang.String
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.static java.lang.String
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.
-
Constructor Summary
Constructors Constructor Description X509PEMFileReader(java.io.File pemFile)
Creates a new X.509 PEM file reader that will read certificate information from the specified file.X509PEMFileReader(java.io.InputStream inputStream)
Creates a new X.509 PEM file reader that will read certificate information from the provided input stream.X509PEMFileReader(java.lang.String pemFilePath)
Creates a new X.509 PEM file reader that will read certificate information from the specified file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this X.509 PEM file reader.X509Certificate
readCertificate()
Reads the next certificate from the PEM file.
-
-
-
Field Detail
-
BEGIN_CERTIFICATE_HEADER
@NotNull public static final java.lang.String 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:
- Constant Field Values
-
END_CERTIFICATE_FOOTER
@NotNull public static final java.lang.String 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:
- Constant Field Values
-
-
Constructor Detail
-
X509PEMFileReader
public X509PEMFileReader(@NotNull java.lang.String pemFilePath) throws java.io.IOException
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 benull
and the file must exist.- Throws:
java.io.IOException
- If a problem occurs while attempting to open the file for reading.
-
X509PEMFileReader
public X509PEMFileReader(@NotNull java.io.File pemFile) throws java.io.IOException
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 benull
and the file must exist.- Throws:
java.io.IOException
- If a problem occurs while attempting to open the file for reading.
-
X509PEMFileReader
public X509PEMFileReader(@NotNull java.io.InputStream inputStream)
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 benull
and it must be open for reading.
-
-
Method Detail
-
readCertificate
@Nullable public X509Certificate readCertificate() throws java.io.IOException, CertException
Reads the next certificate from the PEM file.- Returns:
- The certificate that was read, or
null
if the end of the file has been reached. - Throws:
java.io.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
public void close() throws java.io.IOException
Closes this X.509 PEM file reader.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
- If a problem is encountered while attempting to close the reader.
-
-