@Beta public final class PemReader extends Object
Beta
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:
Modifier and Type | Class and Description |
---|---|
static class |
PemReader.Section
Section in the PEM file.
|
Modifier and Type | Method and Description |
---|---|
void |
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.
|
PemReader.Section |
readNextSection()
Reads the next section in the PEM file or
null for end of file. |
PemReader.Section |
readNextSection(String titleToLookFor)
Reads the next section in the PEM file, optionally based on a title to look for.
|
public PemReader(Reader reader)
reader
- readerpublic PemReader.Section readNextSection() throws IOException
null
for end of file.IOException
public PemReader.Section readNextSection(String titleToLookFor) throws IOException
titleToLookFor
- title to look for or null
for any titlenull
for end of fileIOException
public static PemReader.Section readFirstSectionAndClose(Reader reader) throws IOException
reader
- readernull
for none foundIOException
public static PemReader.Section readFirstSectionAndClose(Reader reader, String titleToLookFor) throws IOException
titleToLookFor
- title to look for or null
for any titlereader
- readernull
for none foundIOException
public void close() throws IOException
To ensure that the stream is closed properly, call close()
in a finally block.
IOException
Copyright © 2011–2020 Google. All rights reserved.