com.sun.management.snmp
Class BerDecoder

java.lang.Object
  extended by com.sun.management.snmp.BerDecoder

public class BerDecoder
extends Object

The BerDecoder class is used for decoding BER-encoded data. A BerDecoder needs to be set up with the byte string containing the encoding. It maintains a current position in the byte string. Methods allows to fetch integer, string, OID, etc., from the current position. After a fetch the current position is moved forward. A fetch throws a BerException if the encoding is not of the expected type.

Since:
Java DMK 5.1

Field Summary
static int BooleanTag
           
static int IntegerTag
           
static int NullTag
           
static int OctetStringTag
           
static int OidTag
           
static int SequenceTag
           
 
Constructor Summary
BerDecoder(byte[] b)
          Constructs a new decoder and attaches it to the specified byte string.
 
Method Summary
 boolean cannotCloseSequence()
          Return true if the end of the current sequence is not reached.
 void closeSequence()
          Close a sequence.
 byte[] fetchAny()
          Fetch an ANY value.
 byte[] fetchAny(int tag)
          Fetch an ANY value with a specific tag.
 int fetchInteger()
          Fetch an integer.
 int fetchInteger(int tag)
          Fetch an integer with the specified tag.
 long fetchIntegerAsLong()
          Fetch an integer and return a long value.
 long fetchIntegerAsLong(int tag)
          Fetch an integer with the specified tag and return a long value.
 void fetchNull()
          Fetch a NULL value.
 void fetchNull(int tag)
          Fetch a NULL value with a specified tag.
 byte[] fetchOctetString()
          Fetch an octet string.
 byte[] fetchOctetString(int tag)
          Fetch an octet string with a specified tag.
 long[] fetchOid()
          Fetch an object identifier.
 long[] fetchOid(int tag)
          Fetch an object identifier with a specified tag.
 int getTag()
          Get the tag of the data at the current position.
 void openSequence()
          Fetch a sequence header.
 void openSequence(int tag)
          Fetch a sequence header with a specific tag.
 void reset()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BooleanTag

public static final int BooleanTag
See Also:
Constant Field Values

IntegerTag

public static final int IntegerTag
See Also:
Constant Field Values

OctetStringTag

public static final int OctetStringTag
See Also:
Constant Field Values

NullTag

public static final int NullTag
See Also:
Constant Field Values

OidTag

public static final int OidTag
See Also:
Constant Field Values

SequenceTag

public static final int SequenceTag
See Also:
Constant Field Values
Constructor Detail

BerDecoder

public BerDecoder(byte[] b)
Constructs a new decoder and attaches it to the specified byte string.

Parameters:
b - The byte string containing the encoded data.
Method Detail

reset

public void reset()

fetchInteger

public int fetchInteger()
                 throws BerException
Fetch an integer.

Returns:
The decoded integer.
Throws:
BerException - Current position does not point to an integer.

fetchInteger

public int fetchInteger(int tag)
                 throws BerException
Fetch an integer with the specified tag.

Parameters:
tag - The expected tag.
Returns:
The decoded integer.
Throws:
BerException - Current position does not point to an integer or the tag is not the expected one.

fetchIntegerAsLong

public long fetchIntegerAsLong()
                        throws BerException
Fetch an integer and return a long value.

Returns:
The decoded integer.
Throws:
BerException - Current position does not point to an integer.

fetchIntegerAsLong

public long fetchIntegerAsLong(int tag)
                        throws BerException
Fetch an integer with the specified tag and return a long value.

Parameters:
tag - The expected tag.
Returns:
The decoded integer.
Throws:
BerException - Current position does not point to an integer or the tag is not the expected one.

fetchOctetString

public byte[] fetchOctetString()
                        throws BerException
Fetch an octet string.

Returns:
The decoded string.
Throws:
BerException - Current position does not point to an octet string.

fetchOctetString

public byte[] fetchOctetString(int tag)
                        throws BerException
Fetch an octet string with a specified tag.

Parameters:
tag - The expected tag.
Returns:
The decoded string.
Throws:
BerException - Current position does not point to an octet string or the tag is not the expected one.

fetchOid

public long[] fetchOid()
                throws BerException
Fetch an object identifier.

Returns:
The decoded object identifier as an array of long.
Throws:
BerException

fetchOid

public long[] fetchOid(int tag)
                throws BerException
Fetch an object identifier with a specified tag.

Parameters:
tag - The expected tag.
Returns:
The decoded object identifier as an array of long.
Throws:
BerException - Current position does not point to an oid or the tag is not the expected one.

fetchNull

public void fetchNull()
               throws BerException
Fetch a NULL value.

Throws:
BerException - Current position does not point to NULL value.

fetchNull

public void fetchNull(int tag)
               throws BerException
Fetch a NULL value with a specified tag.

Parameters:
tag - The expected tag.
Throws:
BerException - Current position does not point to NULL value or the tag is not the expected one.

fetchAny

public byte[] fetchAny()
                throws BerException
Fetch an ANY value. In fact, this method does not decode anything it simply returns the next TLV as an array of bytes.

Returns:
The TLV as a byte array.
Throws:
BerException - The next TLV is really badly encoded...

fetchAny

public byte[] fetchAny(int tag)
                throws BerException
Fetch an ANY value with a specific tag.

Parameters:
tag - The expected tag.
Returns:
The TLV as a byte array.
Throws:
BerException - The next TLV is really badly encoded...

openSequence

public void openSequence()
                  throws BerException
Fetch a sequence header. The decoder computes the end position of the sequence and push it on its stack.

Throws:
BerException - Current position does not point to a sequence header.

openSequence

public void openSequence(int tag)
                  throws BerException
Fetch a sequence header with a specific tag.

Parameters:
tag - The expected tag.
Throws:
BerException - Current position does not point to a sequence header or the tag is not the expected one.

closeSequence

public void closeSequence()
                   throws BerException
Close a sequence. The decode pull the stack and verifies that the current position matches with the calculated end of the sequence. If not it throws an exception.

Throws:
BerException - The sequence is not expected to finish here.

cannotCloseSequence

public boolean cannotCloseSequence()
Return true if the end of the current sequence is not reached. When this method returns false, closeSequence can (and must) be invoked.

Returns:
true if there is still some data in the sequence.

getTag

public int getTag()
           throws BerException
Get the tag of the data at the current position. Current position is unchanged.

Returns:
The next tag.
Throws:
BerException

toString

public String toString()
Overrides:
toString in class Object

Open Source build 02
opendmk-1.0-b02 2007.10.01_19:17:46_MEST

Copyright 1998-2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.