Package com.google.api.client.util
Class PemReader
- java.lang.Object
-
- com.google.api.client.util.PemReader
-
@Beta public final class PemReader extends Object
Beta
PEM file reader.Supports reading any PEM stream that contains Base64 encoded content stored inside
"-----BEGIN ...-----"and"-----END ...-----"tags. Each call toreadNextSection()parses the next section in the PEM file. If you need a section of a certain title usereadNextSection(String), for examplereadNextSection("PRIVATE KEY"). To ensure that the stream is closed properly, callclose()in a finally block.As a convenience, use
readFirstSectionAndClose(Reader)orreadFirstSectionAndClose(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
- Author:
- Yaniv Inbar
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPemReader.SectionSection in the PEM file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the reader.static PemReader.SectionreadFirstSectionAndClose(Reader reader)Reads the first section in the PEM file, and then closes the reader.static PemReader.SectionreadFirstSectionAndClose(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.PemReader.SectionreadNextSection()Reads the next section in the PEM file ornullfor end of file.PemReader.SectionreadNextSection(String titleToLookFor)Reads the next section in the PEM file, optionally based on a title to look for.
-
-
-
Constructor Detail
-
PemReader
public PemReader(Reader reader)
- Parameters:
reader- reader
-
-
Method Detail
-
readNextSection
public PemReader.Section readNextSection() throws IOException
Reads the next section in the PEM file ornullfor end of file.- Throws:
IOException
-
readNextSection
public PemReader.Section readNextSection(String titleToLookFor) throws IOException
Reads the next section in the PEM file, optionally based on a title to look for.- Parameters:
titleToLookFor- title to look for ornullfor any title- Returns:
- next section or
nullfor end of file - Throws:
IOException
-
readFirstSectionAndClose
public static PemReader.Section readFirstSectionAndClose(Reader reader) throws IOException
Reads the first section in the PEM file, and then closes the reader.- Parameters:
reader- reader- Returns:
- first section found or
nullfor 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:
titleToLookFor- title to look for ornullfor any titlereader- reader- Returns:
- first section found or
nullfor none found - Throws:
IOException
-
close
public void close() throws IOExceptionCloses the reader.To ensure that the stream is closed properly, call
close()in a finally block.- Throws:
IOException
-
-