com.objsys.asn1j.runtime
Class Asn1DecodeBuffer

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1MessageBuffer
      extended by com.objsys.asn1j.runtime.Asn1DecodeBuffer
Direct Known Subclasses:
Asn1BerDecodeBuffer, Asn1PerDecodeBuffer

public abstract class Asn1DecodeBuffer
extends Asn1MessageBuffer

This is the base class to specific decode buffer classes for the different types of encoding rules (BER, DER and PER).


Field Summary
protected  int mByteCount
           
 
Method Summary
 void addCaptureBuffer(java.io.ByteArrayOutputStream buffer)
          This method is used to add a capture buffer to the internal capture buffer list.
 void addNamedEventHandler(Asn1NamedEventHandler handler)
          This method adds a named event handler to the named event handler list for this buffer.
 void capture(int nbytes)
          This method captures bytes from the input stream to a separate object for later analysis.
 long decodeIntValue(int length, boolean signExtend)
          This method decodes the contents of an ASN.1 integer value.
 int[] decodeOIDContents(int llen)
          This method decodes the contents of an ASN.1 object identifier value.
 int[] decodeRelOIDContents(int llen)
          This method decodes the contents of an ASN.1 relative object identifier value.
 int getByteCount()
          This method returns the count of bytes currently read from the message being decoded.
 int getEventHandlerListCount()
          This method returns number of elements in the event handler list in this object.
 java.io.InputStream getInputStream()
          This method returns a reference to the current current decode input stream object.
 boolean hasEventHandlers()
          This method returns true if, the buffer has event handlers set.
 void hexDump()
          This method provides a hex dump of the bytes in the message being decoded.
protected  void init()
          This method initializes the input stream for decoding.
 void invokeCharacters(java.lang.String svalue)
          This method is used by the event handling logic to invoke the 'characters' event handling method when message contents are parsed.
 void invokeEndElement(java.lang.String name, int index)
          This method is used by the event handling logic to invoke the 'endElement' event handling method when parsing of an element within a message is completed.
 void invokeStartElement(java.lang.String name, int index)
          This method is used by the event handling logic to invoke the 'startElement' event handling method when parsing of an element within a message is started.
 void mark(int readLimit)
          This method is used to mark the current position in the input stream for retry processing.
 int read()
          The read method reads a single byte from the current input stream and returns it to the caller.
 void read(byte[] buffer)
          This version of the read method reads the number of bytes equal to the length of the given input buffer.
 void read(byte[] buffer, int offset, int nbytes)
          This version of the read method reads the given number of bytes from the current input stream and writes them to the specified byte array at the given offset.
abstract  int readByte()
          This abstract method returns the next available 8-bit value from the input stream.
 void removeCaptureBuffer(java.io.ByteArrayOutputStream buffer)
          This method is used to remove a capture buffer from the internal capture buffer list.
 void reset()
          This method is used to reset the current position in the input stream back to the location of the last 'mark' call.
 void setEventHandlerList(Asn1DecodeBuffer buffer)
          This method will set the event handler list in this object to be equal to that in the given decode buffer object.
 void setInputStream(byte[] msgdata, int offset, int length)
          This method will set the input stream from which data is read.
 void setTypeCode(short code)
          This method will sets the internal type code to the given value.
 long skip(long nbytes)
          This method will skip over the requested number of bytes in the input stream.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBuffer
hexDump, hexDump, setKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mByteCount

protected int mByteCount
Method Detail

addNamedEventHandler

public void addNamedEventHandler(Asn1NamedEventHandler handler)
This method adds a named event handler to the named event handler list for this buffer.

Parameters:
handler - Asn1NamedEventHandler object to be added

capture

public void capture(int nbytes)
             throws Asn1EndOfBufferException,
                    java.io.IOException
This method captures bytes from the input stream to a separate object for later analysis.

Parameters:
nbytes - Number of bytes to capture
Throws:
Asn1EndOfBufferException
java.io.IOException

decodeIntValue

public long decodeIntValue(int length,
                           boolean signExtend)
                    throws Asn1Exception,
                           java.io.IOException
This method decodes the contents of an ASN.1 integer value. It can be used for either BER or PER decoding.

Parameters:
length - Length of encoded contents
signExtend - Sign-extend the decoded value to form a 2's comp result
Returns:
Decoded long integer value
Throws:
Asn1Exception
java.io.IOException

decodeOIDContents

public int[] decodeOIDContents(int llen)
                        throws Asn1Exception,
                               java.io.IOException
This method decodes the contents of an ASN.1 object identifier value. It can be used for either BER or PER decoding.

Parameters:
llen - Length of encoded contents
Returns:
Decoded object identifier value
Throws:
Asn1Exception
java.io.IOException

decodeRelOIDContents

public int[] decodeRelOIDContents(int llen)
                           throws Asn1Exception,
                                  java.io.IOException
This method decodes the contents of an ASN.1 relative object identifier value. It can be used for either BER or PER decoding.

Parameters:
llen - Length of encoded contents
Returns:
Decoded object identifier value
Throws:
Asn1Exception
java.io.IOException

addCaptureBuffer

public void addCaptureBuffer(java.io.ByteArrayOutputStream buffer)
This method is used to add a capture buffer to the internal capture buffer list. A capture buffer is used to capture all bytes read from this position forward from the input stream.

Parameters:
buffer - Buffer into which captured bytes are to be stored

removeCaptureBuffer

public void removeCaptureBuffer(java.io.ByteArrayOutputStream buffer)
This method is used to remove a capture buffer from the internal capture buffer list. The add and remove methods can be used to get a set of raw bytes from the input stream for further processing.

Parameters:
buffer - Buffer in which captured bytes stored

getByteCount

public int getByteCount()
This method returns the count of bytes currently read from the message being decoded.

Returns:
Count of bytes read from input stream

getInputStream

public java.io.InputStream getInputStream()
This method returns a reference to the current current decode input stream object.

Specified by:
getInputStream in class Asn1MessageBuffer
Returns:
New input stream object containing encoded message

getEventHandlerListCount

public int getEventHandlerListCount()
This method returns number of elements in the event handler list in this object.

Returns:
number of elements in the event handler list.

hasEventHandlers

public final boolean hasEventHandlers()
This method returns true if, the buffer has event handlers set.

Returns:
true, if the buffer has event handlers. false, otherwise.

hexDump

public void hexDump()
This method provides a hex dump of the bytes in the message being decoded.


init

protected void init()
This method initializes the input stream for decoding.


invokeCharacters

public void invokeCharacters(java.lang.String svalue)
This method is used by the event handling logic to invoke the 'characters' event handling method when message contents are parsed.

Parameters:
svalue - Stringified representation of a parsed value field

invokeEndElement

public void invokeEndElement(java.lang.String name,
                             int index)
This method is used by the event handling logic to invoke the 'endElement' event handling method when parsing of an element within a message is completed.

Parameters:
name - Name of the element
index - Index of element if SEQUENCE OF or SET OF element

invokeStartElement

public void invokeStartElement(java.lang.String name,
                               int index)
This method is used by the event handling logic to invoke the 'startElement' event handling method when parsing of an element within a message is started.

Parameters:
name - Name of the element
index - Index of element if SEQUENCE OF or SET OF element

mark

public void mark(int readLimit)
This method is used to mark the current position in the input stream for retry processing. It is equivalent to the Java InputStream 'mark' method.

Parameters:
readLimit - Max number of bytes that can be read before mark becomes invalid.

read

public final int read()
               throws Asn1EndOfBufferException,
                      java.io.IOException
The read method reads a single byte from the current input stream and returns it to the caller. It will also write the byte out to all registered capture buffers.

Returns:
byte that was read from the input stream
Throws:
Asn1EndOfBufferException - if at end-of-stream
java.io.IOException - Java I/O error

readByte

public abstract int readByte()
                      throws Asn1Exception,
                             java.io.IOException
This abstract method returns the next available 8-bit value from the input stream. It is implemented differently for BER/DER and PER to take into account odd alignments in PER.

Returns:
Next 8-bit byte value from input stream
Throws:
Asn1Exception
java.io.IOException

read

public final void read(byte[] buffer,
                       int offset,
                       int nbytes)
                throws Asn1EndOfBufferException,
                       java.io.IOException
This version of the read method reads the given number of bytes from the current input stream and writes them to the specified byte array at the given offset. It also writes the data to all registered capture buffers.

Parameters:
buffer - the buffer into which the data is read
offset - the start offset of the data
nbytes - number of bytes to read
Throws:
Asn1EndOfBufferException - if at end-of-stream
java.io.IOException - Java I/O error

read

public void read(byte[] buffer)
          throws Asn1EndOfBufferException,
                 java.io.IOException
This version of the read method reads the number of bytes equal to the length of the given input buffer.

Parameters:
buffer - the buffer into which the data is read
Throws:
Asn1EndOfBufferException - if at end-of-stream
java.io.IOException - Java I/O error

reset

public void reset()
This method is used to reset the current position in the input stream back to the location of the last 'mark' call. It is equivalent to the Java InputStream 'reset' method.


setInputStream

public void setInputStream(byte[] msgdata,
                           int offset,
                           int length)
This method will set the input stream from which data is read. This version of the method allows a byte array containing encoded data to be specified.

Parameters:
msgdata - Byte array containing encoded message data
offset - Starting offset of data in the byte array
length - Length (in bytes) of the encoded data

setEventHandlerList

public void setEventHandlerList(Asn1DecodeBuffer buffer)
This method will set the event handler list in this object to be equal to that in the given decode buffer object.

Parameters:
buffer - Decode buffer object

setTypeCode

public final void setTypeCode(short code)
This method will sets the internal type code to the given value. This is a code describing the last type parsed by the decoder.

Parameters:
code - Type code (codes are defined in Asn1Type.java). The codes correspond to the UNIVERSAL tag ID values for the built-in types.

skip

public long skip(long nbytes)
          throws java.io.IOException
This method will skip over the requested number of bytes in the input stream.

Parameters:
nbytes - Number of bytes to skip
Throws:
java.io.IOException