public class

BerEncoder

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

Class Overview

The BerEncoder class is used for encoding data using BER. A BerEncoder needs to be set up with a byte buffer. The encoded data are stored in this byte buffer.

NOTE : the buffer is filled from end to start. This means the caller needs to encode its data in the reverse order.

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
Fields
protected final byte[] bytes
protected final int[] stackBuf
protected int stackTop
protected int start
Public Constructors
BerEncoder(byte[] b)
Constructs a new encoder and attaches it to the specified byte string.
Public Methods
void closeSequence()
Close a sequence.
void closeSequence(int tag)
Close a sequence with the specified tag.
void openSequence()
Open a sequence.
void putAny(byte[] s)
Put an ANY value.
void putAny(byte[] s, int byteCount)
Put an ANY value.
void putInteger(int v)
Put an integer.
void putInteger(long v)
Put an integer expressed as a long.
void putInteger(long v, int tag)
Put an integer expressed as a long with the specified tag.
void putInteger(int v, int tag)
Put an integer with the specified tag.
void putNull(int tag)
Put a NULL value with a specified tag.
void putNull()
Put a NULL value.
void putOctetString(byte[] s)
Put an octet string.
void putOctetString(byte[] s, int tag)
Put an octet string with a specified tag.
void putOid(long[] s, int tag)
Put an object identifier with a specified tag.
void putOid(long[] s)
Put an object identifier.
int trim()
Trim the encoding data and returns the length of the encoding.
Protected Methods
final void putIntegerValue(long v)
Put an integer value expressed as a long.
final void putIntegerValue(int v)
Put an integer value and move the current position backward.
final void putLength(int length)
Put a length and move the current position backward.
final void putOidValue(long[] s)
Put an oid and move the current position backward.
final void putStringValue(byte[] s)
Put a byte string and move the current position backward.
final void putTag(int tag)
Put a tag and move the current position backward.
[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)

Fields

protected final byte[] bytes

protected final int[] stackBuf

protected int stackTop

protected int start

Public Constructors

public BerEncoder (byte[] b)

Constructs a new encoder and attaches it to the specified byte string.

Parameters
b The byte string containing the encoded data.

Public Methods

public void closeSequence ()

Close a sequence. The decode pull the stack to know the end of the current sequence.

public void closeSequence (int tag)

Close a sequence with the specified tag.

public void openSequence ()

Open a sequence. The encoder push the current position on its stack.

public void putAny (byte[] s)

Put an ANY value. In fact, this method does not encode anything. It simply copies the specified bytes into the encoding.

Parameters
s The encoding of the ANY value.

public void putAny (byte[] s, int byteCount)

Put an ANY value. Only the first byteCount are considered.

Parameters
s The encoding of the ANY value.
byteCount The number of bytes of the encoding.

public void putInteger (int v)

Put an integer.

Parameters
v The integer to encode.

public void putInteger (long v)

Put an integer expressed as a long.

Parameters
v The long to encode.

public void putInteger (long v, int tag)

Put an integer expressed as a long with the specified tag.

Parameters
v The long to encode
tag The tag to encode.

public void putInteger (int v, int tag)

Put an integer with the specified tag.

Parameters
v The integer to encode.
tag The tag to encode.

public void putNull (int tag)

Put a NULL value with a specified tag.

Parameters
tag The tag to encode.

public void putNull ()

Put a NULL value.

public void putOctetString (byte[] s)

Put an octet string.

Parameters
s The bytes to encode

public void putOctetString (byte[] s, int tag)

Put an octet string with a specified tag.

Parameters
s The bytes to encode
tag The tag to encode.

public void putOid (long[] s, int tag)

Put an object identifier with a specified tag.

Parameters
s The integer to encode.
tag The tag to encode.

public void putOid (long[] s)

Put an object identifier.

Parameters
s The oid to encode.

public int trim ()

Trim the encoding data and returns the length of the encoding. The encoder does backward encoding : so the bytes buffer is filled from end to start. The encoded data must be shift before the buffer can be used. This is the purpose of the trim method. After a call to the trim method, the encoder is reinitialized and putXXX overwrite any existing encoded data.

Returns
  • The length of the encoded data.

Protected Methods

protected final void putIntegerValue (long v)

Put an integer value expressed as a long.

Parameters
v The integer to encode.

protected final void putIntegerValue (int v)

Put an integer value and move the current position backward.

Parameters
v The integer to encode.

protected final void putLength (int length)

Put a length and move the current position backward.

Parameters
length The length to encode.

protected final void putOidValue (long[] s)

Put an oid and move the current position backward.

Parameters
s The oid to encode.

protected final void putStringValue (byte[] s)

Put a byte string and move the current position backward.

Parameters
s The byte string to encode.

protected final void putTag (int tag)

Put a tag and move the current position backward.

Parameters
tag The tag to encode.