com.sun.slamd.asn1
Class ASN1Reader

java.lang.Object
  extended by com.sun.slamd.asn1.ASN1Reader

public class ASN1Reader
extends java.lang.Object

This class provides a mechanism for reading ASN.1 elements from an input stream. It is not a true java.io.Reader, but it should be good enough for most purposes.

Author:
Neil A. Wilson

Field Summary
static int BUFFER_SIZE
          The size of the buffer that will be used for reading in data.
 
Constructor Summary
ASN1Reader(java.io.InputStream inputStream)
          Creates a new ASN.1 reader to read elements from the specified input stream.
ASN1Reader(java.net.Socket socket)
          Creates a new ASN.1 reader to read elements from the input stream of the provided socket.
 
Method Summary
 int available()
          Retrieves the number of bytes that can be read without blocking.
 void close()
          Closes this ASN.1 reader.
 ASN1Element readElement()
          Reads an ASN.1 element from the provided input stream.
 ASN1Element readElement(int timeout)
          Reads an ASN.1 element from the provided input stream, waiting a maximum of timeout milliseconds for the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
The size of the buffer that will be used for reading in data.

See Also:
Constant Field Values
Constructor Detail

ASN1Reader

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

Parameters:
inputStream - The input stream from which ASN.1 elements are to be read.

ASN1Reader

public ASN1Reader(java.net.Socket socket)
           throws java.io.IOException
Creates a new ASN.1 reader to read elements from the input stream of the provided socket.

Parameters:
socket - The network socket from which the ASN.1 elements are to be read.
Throws:
java.io.IOException - If the socket's input stream cannot be obtained.
Method Detail

available

public int available()
              throws java.io.IOException
Retrieves the number of bytes that can be read without blocking.

Returns:
The number of bytes that can be read without blocking.
Throws:
java.io.IOException - If a problem occurs while trying to make the determination.

readElement

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

Returns:
The ASN.1 element that was read, or null if there was no more data to read.
Throws:
ASN1Exception - If the data read from the input stream does not contain a valid ASN.1 element.
java.io.IOException - If there is a problem reading the information from the input stream.

readElement

public ASN1Element readElement(int timeout)
                        throws ASN1Exception,
                               java.io.InterruptedIOException,
                               java.io.IOException
Reads an ASN.1 element from the provided input stream, waiting a maximum of timeout milliseconds for the response. If no response has been received during that time, then an InterruptedIOException will be thrown. Note that this is only applicable to ASN.1 readers that were created using the version of the constructor that accepts a socket as the argument. If no socket has been provided, then no timeout will be used.

Parameters:
timeout - The maximum length of time in milliseconds that the read operation will be allowed to block while waiting for information.
Returns:
The ASN.1 element that was read.
Throws:
ASN1Exception - If the data read from the input stream does not contain a valid ASN.1 element.
java.io.InterruptedIOException - If the read was interrupted because the timeout was reached.
java.io.IOException - If there is a problem reading the information from the input stream or setting a timeout on the socket.

close

public void close()
           throws java.io.IOException
Closes this ASN.1 reader.

Throws:
java.io.IOException - If a problem occurs while closing the ASN.1 reader.