@Mutable @ThreadSafety(level=NOT_THREADSAFE) public final class ASN1StreamReader extends java.lang.Object implements java.io.Closeable
ASN1Element
objects if they are not
needed. If any method in this class throws an IOException
, then the
caller must close this reader and must not attempt to use it any more.
ASN1StreamReader
instances are not threadsafe and must not be
accessed concurrently by multiple threads.Constructor and Description |
---|
ASN1StreamReader(java.io.InputStream inputStream)
Creates a new ASN.1 stream reader that will read data from the provided
input stream.
|
ASN1StreamReader(java.io.InputStream inputStream,
int maxElementSize)
Creates a new ASN.1 stream reader that will read data from the provided
input stream.
|
Modifier and Type | Method and Description |
---|---|
ASN1StreamReaderSequence |
beginSequence()
Reads the beginning of an ASN.1 sequence from the input stream and
returns a value that can be used to determine when the end of the sequence
has been reached.
|
ASN1StreamReaderSet |
beginSet()
Reads the beginning of an ASN.1 set from the input stream and returns a
value that can be used to determine when the end of the set has been
reached.
|
void |
close()
Closes this ASN.1 stream reader and the underlying input stream.
|
boolean |
ignoreInitialSocketTimeoutException()
Indicates whether to ignore
java.net.SocketTimeoutException
exceptions that may be caught while trying to read the first byte of an
element. |
boolean |
ignoreSocketTimeoutException()
Deprecated.
Use the
ignoreInitialSocketTimeoutException() and
ignoreSubsequentSocketTimeoutException() methods
instead. |
boolean |
ignoreSubsequentSocketTimeoutException()
Indicates whether to ignore
java.net.SocketTimeoutException
exceptions that may be caught while trying to read subsequent bytes of an
element (after one or more bytes have already been read for that element). |
int |
peek()
Peeks at the next byte to be read from the input stream without actually
consuming it.
|
java.math.BigInteger |
readBigInteger()
Reads an ASN.1 integer element from the input stream and returns the value
as a
BigInteger . |
java.lang.Boolean |
readBoolean()
Reads an ASN.1 Boolean element from the input stream and returns the value
as a
Boolean . |
byte[] |
readBytes()
Reads an ASN.1 octet string element from the input stream and returns the
value as a byte array.
|
ASN1Element |
readElement()
Reads a complete ASN.1 element from the input stream.
|
java.lang.Integer |
readEnumerated()
Reads an ASN.1 enumerated element from the input stream and returns the
value as an
Integer . |
java.util.Date |
readGeneralizedTime()
Reads an ASN.1 generalized time element from the input stream and returns
the value as a
Date . |
java.lang.Integer |
readInteger()
Reads an ASN.1 integer element from the input stream and returns the value
as an
Integer . |
java.lang.Long |
readLong()
Reads an ASN.1 integer element from the input stream and returns the value
as a
Long . |
void |
readNull()
Reads an ASN.1 null element from the input stream.
|
java.lang.String |
readString()
Reads an ASN.1 octet string element from the input stream and returns the
value as a
String using the UTF-8 encoding. |
java.util.Date |
readUTCTime()
Reads an ASN.1 UTC time element from the input stream and returns the value
as a
Date . |
void |
setIgnoreSocketTimeout(boolean ignoreSocketTimeout)
Deprecated.
Use the
setIgnoreSocketTimeout(boolean,boolean)
method instead. |
void |
setIgnoreSocketTimeout(boolean ignoreInitialSocketTimeout,
boolean ignoreSubsequentSocketTimeout)
Indicates whether to ignore
java.net.SocketTimeoutException
exceptions that may be caught during processing. |
public ASN1StreamReader(@NotNull java.io.InputStream inputStream)
LDAPConnectionOptions.getMaxMessageSize()
method.inputStream
- The input stream from which data should be read. If
the provided input stream does not support the use of
the mark
and reset
methods, then it
will be wrapped with a BufferedInputStream
.public ASN1StreamReader(@NotNull java.io.InputStream inputStream, int maxElementSize)
Integer.MAX_VALUE
.inputStream
- The input stream from which data should be read.
If the provided input stream does not support the
use of the mark
and reset
methods,
then it will be wrapped with a
BufferedInputStream
.maxElementSize
- The maximum size in bytes of an ASN.1 element that
may be read. A value less than or equal to zero
will be interpreted as Integer.MAX_VALUE
.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- If a problem occurs while closing the underlying
input stream.@Deprecated public boolean ignoreSocketTimeoutException()
ignoreInitialSocketTimeoutException()
and
ignoreSubsequentSocketTimeoutException()
methods
instead.java.net.SocketTimeoutException
exceptions that may be caught during processing.true
if SocketTimeoutException
exceptions should
be ignored, or false
if they should not be ignored and
should be propagated to the caller.public boolean ignoreInitialSocketTimeoutException()
java.net.SocketTimeoutException
exceptions that may be caught while trying to read the first byte of an
element.true
if SocketTimeoutException
exceptions should
be ignored while trying to read the first byte of an element, or
false
if they should not be ignored and should be
propagated to the caller.public boolean ignoreSubsequentSocketTimeoutException()
java.net.SocketTimeoutException
exceptions that may be caught while trying to read subsequent bytes of an
element (after one or more bytes have already been read for that element).true
if SocketTimeoutException
exceptions should
be ignored while trying to read subsequent bytes of an element, or
false
if they should not be ignored and should be
propagated to the caller.@Deprecated public void setIgnoreSocketTimeout(boolean ignoreSocketTimeout)
setIgnoreSocketTimeout(boolean,boolean)
method instead.java.net.SocketTimeoutException
exceptions that may be caught during processing.ignoreSocketTimeout
- Indicates whether to ignore
SocketTimeoutException
exceptions that
may be caught during processing.public void setIgnoreSocketTimeout(boolean ignoreInitialSocketTimeout, boolean ignoreSubsequentSocketTimeout)
java.net.SocketTimeoutException
exceptions that may be caught during processing.ignoreInitialSocketTimeout
- Indicates whether to ignore
SocketTimeoutException
exceptions that may be caught while
trying to read the first byte of an
element.ignoreSubsequentSocketTimeout
- Indicates whether to ignore
SocketTimeoutException
exceptions that may be caught while
reading beyond the first byte of an
element.public int peek() throws java.io.IOException
java.io.IOException
- If a problem occurs while reading from the input
stream.@Nullable public ASN1Element readElement() throws java.io.IOException
null
if
the end of the input stream was reached before any data could be
read. If null
is returned, then the input stream will
have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.@Nullable public java.lang.Boolean readBoolean() throws java.io.IOException, ASN1Exception
Boolean
.Boolean
value of the ASN.1 Boolean element read, or
null
if the end of the input stream was reached before any
data could be read. If null
is returned, then the input
stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1
Boolean element.@Nullable public java.lang.Integer readEnumerated() throws java.io.IOException, ASN1Exception
Integer
.Integer
value of the ASN.1 enumerated element read, or
null
if the end of the input stream was reached before any
data could be read. If null
is returned, then the input
stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1
enumerated element.@Nullable public java.util.Date readGeneralizedTime() throws java.io.IOException, ASN1Exception
Date
.Date
value of the ASN.1 generalized time element read,
or null
if the end of the input stream was reached before
any data could be read. If null
is returned, then the
input stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1
generalized time element.@Nullable public java.lang.Integer readInteger() throws java.io.IOException, ASN1Exception
Integer
.Integer
value of the ASN.1 integer element read, or
null
if the end of the input stream was reached before any
data could be read. If null
is returned, then the input
stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1
integer element.@Nullable public java.lang.Long readLong() throws java.io.IOException, ASN1Exception
Long
.Long
value of the ASN.1 integer element read, or
null
if the end of the input stream was reached before any
data could be read. If null
is returned, then the input
stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1
integer element.@Nullable public java.math.BigInteger readBigInteger() throws java.io.IOException, ASN1Exception
BigInteger
.BigInteger
value of the ASN.1 integer element read, or
null
if the end of the input stream was reached before any
data could be read. If null
is returned, then the input
stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1
integer element.public void readNull() throws java.io.IOException, ASN1Exception
java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1 null
element.@Nullable public byte[] readBytes() throws java.io.IOException
null
if the end of the input stream was reached before any
data could be read. If null
is returned, then the input
stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.@Nullable public java.lang.String readString() throws java.io.IOException
String
using the UTF-8 encoding.String
value of the ASN.1 octet string element read,
or null
if the end of the input stream was reached before
any data could be read. If null
is returned, then the
input stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.@Nullable public java.util.Date readUTCTime() throws java.io.IOException, ASN1Exception
Date
.Date
value of the ASN.1 UTC time element read, or
null
if the end of the input stream was reached before any
data could be read. If null
is returned, then the input
stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.ASN1Exception
- If the data read cannot be parsed as an ASN.1 UTC
time element.@Nullable public ASN1StreamReaderSequence beginSequence() throws java.io.IOException
ASN1StreamReaderSequence.hasMoreElements()
method returns
false
.null
if the end of the input
stream was reached before any data could be read. If null
is returned, then the input stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.@Nullable public ASN1StreamReaderSet beginSet() throws java.io.IOException
ASN1StreamReaderSet.hasMoreElements()
method
returns false
.null
if the end of the input stream
was reached before any data could be read. If null
is
returned, then the input stream will have been closed.java.io.IOException
- If a problem occurs while reading from the input
stream, if the end of the input stream is reached in
the middle of the element, or or if an attempt is
made to read an element larger than the maximum
allowed size.