Package com.google.api.client.util
Class PemReader
java.lang.Object
com.google.api.client.util.PemReader
Beta
PEM file reader.
Supports reading any PEM stream that contains Base64 encoded content stored inside
"-----BEGIN ...-----"
and "-----END ...-----"
tags. Each call to
readNextSection()
parses the next section in the PEM file. If you need a section of a
certain title use readNextSection(String)
, for example
readNextSection("PRIVATE KEY")
. To ensure that the stream is closed properly, call
close()
in a finally block.
As a convenience, use readFirstSectionAndClose(Reader)
or
readFirstSectionAndClose(Reader, String)
for the common case of only a single section in
a PEM file (or only a single section of a given title).
Limitations:
- Assumes the PEM file section content is not encrypted and cannot handle the case of any headers inside the BEGIN and END tag.
- It also ignores any attributes associated with any PEM file section.
- Since:
- 1.14
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Pattern
private static final Pattern
private BufferedReader
Reader. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the reader.static PemReader.Section
readFirstSectionAndClose
(Reader reader) Reads the first section in the PEM file, and then closes the reader.static PemReader.Section
readFirstSectionAndClose
(Reader reader, String titleToLookFor) Reads the first section in the PEM file, optionally based on a title to look for, and then closes the reader.Reads the next section in the PEM file ornull
for end of file.readNextSection
(String titleToLookFor) Reads the next section in the PEM file, optionally based on a title to look for.
-
Field Details
-
BEGIN_PATTERN
-
END_PATTERN
-
reader
Reader.
-
-
Constructor Details
-
PemReader
- Parameters:
reader
- reader
-
-
Method Details
-
readNextSection
Reads the next section in the PEM file ornull
for end of file.- Throws:
IOException
-
readNextSection
Reads the next section in the PEM file, optionally based on a title to look for.- Parameters:
titleToLookFor
- title to look for ornull
for any title- Returns:
- next section or
null
for end of file - Throws:
IOException
-
readFirstSectionAndClose
Reads the first section in the PEM file, and then closes the reader.- Parameters:
reader
- reader- Returns:
- first section found or
null
for none found - Throws:
IOException
-
readFirstSectionAndClose
public static PemReader.Section readFirstSectionAndClose(Reader reader, String titleToLookFor) throws IOException Reads the first section in the PEM file, optionally based on a title to look for, and then closes the reader.- Parameters:
reader
- readertitleToLookFor
- title to look for ornull
for any title- Returns:
- first section found or
null
for none found - Throws:
IOException
-
close
Closes the reader.To ensure that the stream is closed properly, call
close()
in a finally block.- Throws:
IOException
-