public class

BerDecoder

extends Object
java.lang.Object
   ↳ com.sun.jmx.snmp.BerDecoder

Class Overview

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.

This API is a Sun Microsystems internal API and is subject to change without notice.

Summary

Constants
int BooleanTag
int IntegerTag
int NullTag
int OctetStringTag
int OidTag
int SequenceTag
Public Constructors
BerDecoder(byte[] b)
Constructs a new decoder and attaches it to the specified byte string.
Public Methods
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(int tag)
Fetch an integer with the specified tag.
int fetchInteger()
Fetch an integer.
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(int tag)
Fetch a NULL value with a specified tag.
void fetchNull()
Fetch a NULL value.
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(int tag)
Fetch a sequence header with a specific tag.
void openSequence()
Fetch a sequence header.
void reset()
String toString()
Returns a string representation of the object.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int BooleanTag

Constant Value: 1 (0x00000001)

public static final int IntegerTag

Constant Value: 2 (0x00000002)

public static final int NullTag

Constant Value: 5 (0x00000005)

public static final int OctetStringTag

Constant Value: 4 (0x00000004)

public static final int OidTag

Constant Value: 6 (0x00000006)

public static final int SequenceTag

Constant Value: 48 (0x00000030)

Public Constructors

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.

Public Methods

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.

public void closeSequence ()

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.

public byte[] fetchAny ()

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...

public byte[] fetchAny (int tag)

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...

public int fetchInteger (int tag)

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.

public int fetchInteger ()

Fetch an integer.

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

public long fetchIntegerAsLong ()

Fetch an integer and return a long value.

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

public long fetchIntegerAsLong (int tag)

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.

public void fetchNull (int tag)

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.

public void fetchNull ()

Fetch a NULL value.

Throws
BerException Current position does not point to NULL value.

public byte[] fetchOctetString ()

Fetch an octet string.

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

public byte[] fetchOctetString (int tag)

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.

public long[] fetchOid ()

Fetch an object identifier.

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

public long[] fetchOid (int tag)

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.

public int getTag ()

Get the tag of the data at the current position. Current position is unchanged.

Returns
  • The next tag.
Throws
BerException

public void openSequence (int tag)

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.

public void openSequence ()

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.

public void reset ()

public String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a string representation of the object.