com.objsys.asn1j.runtime
Class Asn1DecodeBuffer

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1MessageBufferBase
      extended by com.objsys.asn1j.runtime.Asn1MessageBuffer
          extended by com.objsys.asn1j.runtime.Asn1DecodeBuffer
Direct Known Subclasses:
Asn1BerDecodeBuffer, Asn1MderDecodeBuffer, 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
           
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Method Summary
 void addCaptureBuffer(java.io.ByteArrayOutputStream buffer)
          This method is used to add a capture buffer to the internal capture buffer list.
 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.
 java.io.InputStream getInputStream()
          This method returns a reference to the current current decode input stream object.
 boolean getLazyOpenTypeDecode()
          Return true if lazy open type decoding is on.
 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 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.
 int read2Bytes()
          Read the next two bytes from the current input stream into an int, and return that int.
 int read4Bytes()
          Read the next four bytes from the current input stream into an int, and return that int.
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 setInputStream(byte[] msgdata, int offset, int length)
          This method will set the input stream from which data is read.
 void setLazyOpenTypeDecode(boolean value)
          This method turns lazy open type decoding on or off.
 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
addNamedEventHandler, getEventHandlerListCount, hasEventHandlers, invokeCharacters, invokeEndElement, invokeStartElement, setEventHandlerList
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
getContext, hexDump, hexDump, setKey, setTypeCode
 
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

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

getLazyOpenTypeDecode

public boolean getLazyOpenTypeDecode()
Return true if lazy open type decoding is on.

Returns:
true if lazy open type decoding is on

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.


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.

read2Bytes

public final int read2Bytes()
                     throws Asn1EndOfBufferException,
                            java.io.IOException
Read the next two bytes from the current input stream into an int, and return that int. The bytes of the int, from lowest to highest, will correspond to the bytes read from the stream, from last to first. The highest two bytes will be 0. Each byte read will be written to all registered capture buffers.

Returns:
an int representing the 2 bytes read, as described above.
Throws:
Asn1EndOfBufferException - if at end-of-stream
java.io.IOException - Java I/O error

read4Bytes

public final int read4Bytes()
                     throws Asn1EndOfBufferException,
                            java.io.IOException
Read the next four bytes from the current input stream into an int, and return that int. The bytes of the int, from lowest to highest, will correspond to the bytes read from the stream, from last to first. Each byte read will be written to all registered capture buffers.

Returns:
an int representing the 4 bytes read, as described above.
Throws:
Asn1EndOfBufferException - if at end-of-stream
java.io.IOException - Java I/O error

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.


setLazyOpenTypeDecode

public void setLazyOpenTypeDecode(boolean value)
This method turns lazy open type decoding on or off. Its setting is relevant only when generating table constraint code (otherwise, open types cannot be decoded). Generated decode methods check this setting to determine whether to decode open types or not. When lazy open type decoding is turned on, you can use the generated decodeOpenType* methods to decode open types (again, assuming table constraint code was generated).


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

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