org.opends.server.protocols.asn1
Class ASN1Reader

java.lang.Object
  extended by org.opends.server.protocols.asn1.ASN1Reader

@PublicAPI(stability=UNCOMMITTED,
           mayInstantiate=true,
           mayExtend=false,
           mayInvoke=true)
public final class ASN1Reader
extends java.lang.Object

This class defines a utility that can be used to read ASN.1 elements from a provided socket or input stream.


Constructor Summary
ASN1Reader(java.io.InputStream inputStream)
          Creates a new ASN.1 reader that will read elements from the provided input stream.
ASN1Reader(java.net.Socket socket)
          Creates a new ASN.1 reader that will read elements from the provided socket.
 
Method Summary
 void close()
          Closes this ASN.1 reader and the underlying input stream and/or socket.
 int getIOTimeout()
          Retrieves the maximum length of time in milliseconds that this reader will be allowed to block while waiting to read data.
 int getMaxElementSize()
          Retrieves the maximum size in bytes that will be allowed for elements read using this reader.
 ASN1Element readElement()
          Reads an ASN.1 element from the associated input stream.
 void setIOTimeout(int ioTimeout)
          Specifies the maximum length of time in milliseconds that this reader should be allowed to block while waiting to read data.
 void setMaxElementSize(int maxElementSize)
          Specifies the maximum size in bytes that will be allowed for elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ASN1Reader

public ASN1Reader(java.net.Socket socket)
           throws java.io.IOException
Creates a new ASN.1 reader that will read elements from the provided socket.

Parameters:
socket - The socket from which to read the ASN.1 elements.
Throws:
java.io.IOException - If a problem occurs while attempting to obtain the input stream for the socket.

ASN1Reader

public ASN1Reader(java.io.InputStream inputStream)
Creates a new ASN.1 reader that will read elements from the provided input stream.

Parameters:
inputStream - The input stream from which to read the ASN.1 elements.
Method Detail

getMaxElementSize

public int getMaxElementSize()
Retrieves the maximum size in bytes that will be allowed for elements read using this reader. A negative value indicates that no limit should be enforced.

Returns:
The maximum size in bytes that will be allowed for elements.

setMaxElementSize

public void setMaxElementSize(int maxElementSize)
Specifies the maximum size in bytes that will be allowed for elements. A negative value indicates that no limit should be enforced.

Parameters:
maxElementSize - The maximum size in bytes that will be allowed for elements read using this reader.

getIOTimeout

public int getIOTimeout()
                 throws java.io.IOException
Retrieves the maximum length of time in milliseconds that this reader will be allowed to block while waiting to read data. This is only applicable for readers created with sockets rather than input streams.

Returns:
The maximum length of time in milliseconds that this reader will be allowed to block while waiting to read data, or 0 if there is no limit, or -1 if this ASN.1 reader is not associated with a socket and no timeout can be enforced.
Throws:
java.io.IOException - If a problem occurs while polling the socket to determine the timeout.

setIOTimeout

public void setIOTimeout(int ioTimeout)
                  throws java.io.IOException
Specifies the maximum length of time in milliseconds that this reader should be allowed to block while waiting to read data. This will only be applicable for readers created with sockets and will have no effect on readers created with input streams.

Parameters:
ioTimeout - The maximum length of time in milliseconds that this reader should be allowed to block while waiting to read data, or 0 if there should be no limit.
Throws:
java.io.IOException - If a problem occurs while setting the underlying socket option.

readElement

public ASN1Element readElement()
                        throws java.io.IOException,
                               ASN1Exception
Reads an ASN.1 element from the associated input stream.

Returns:
The ASN.1 element read from the associated input stream, or null if the end of the stream has been reached.
Throws:
java.io.IOException - If a problem occurs while attempting to read from the input stream.
ASN1Exception - If a problem occurs while attempting to decode the data read as an ASN.1 element.

close

public void close()
Closes this ASN.1 reader and the underlying input stream and/or socket.