com.sun.management.snmp
Class BerEncoder

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

public class BerEncoder
extends Object

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.

Since:
Java DMK 5.1

Field Summary
static int BooleanTag
           
protected  byte[] bytes
           
static int IntegerTag
           
static int NullTag
           
static int OctetStringTag
           
static int OidTag
           
static int SequenceTag
           
protected  int[] stackBuf
           
protected  int stackTop
           
protected  int start
           
 
Constructor Summary
BerEncoder(byte[] b)
          Constructs a new encoder and attaches it to the specified byte string.
 
Method Summary
 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(int v, int tag)
          Put an integer with the specified tag.
 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.
protected  void putIntegerValue(int v)
          Put an integer value and move the current position backward.
protected  void putIntegerValue(long v)
          Put an integer value expressed as a long.
protected  void putLength(int length)
          Put a length and move the current position backward.
 void putNull()
          Put a NULL value.
 void putNull(int tag)
          Put a NULL value with a specified tag.
 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)
          Put an object identifier.
 void putOid(long[] s, int tag)
          Put an object identifier with a specified tag.
protected  void putOidValue(long[] s)
          Put an oid and move the current position backward.
protected  void putStringValue(byte[] s)
          Put a byte string and move the current position backward.
protected  void putTag(int tag)
          Put a tag and move the current position backward.
 void putUnsignedLong(long v, int tag)
           
protected  void putUnsignedLongValue(long v)
          Put an unsigned long value and move the current position backward.
 int trim()
          Trim the encoding data and returns the length of the encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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

bytes

protected final byte[] bytes

start

protected int start

stackBuf

protected final int[] stackBuf

stackTop

protected int stackTop
Constructor Detail

BerEncoder

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

trim

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.

putInteger

public void putInteger(int v)
Put an integer.

Parameters:
v - The integer to encode.

putInteger

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.

putInteger

public void putInteger(long v)
Put an integer expressed as a long.

Parameters:
v - The long to encode.

putInteger

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.

putOctetString

public void putOctetString(byte[] s)
Put an octet string.

Parameters:
s - The bytes to encode

putOctetString

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.

putOid

public void putOid(long[] s)
Put an object identifier.

Parameters:
s - The oid to encode.

putOid

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.

putNull

public void putNull()
Put a NULL value.


putNull

public void putNull(int tag)
Put a NULL value with a specified tag.

Parameters:
tag - The tag to encode.

putAny

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.

putAny

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.

putUnsignedLong

public void putUnsignedLong(long v,
                            int tag)

openSequence

public void openSequence()
Open a sequence. The encoder push the current position on its stack.


closeSequence

public void closeSequence()
Close a sequence. The decode pull the stack to know the end of the current sequence.


closeSequence

public void closeSequence(int tag)
Close a sequence with the specified tag.


putTag

protected final void putTag(int tag)
Put a tag and move the current position backward.

Parameters:
tag - The tag to encode.

putLength

protected final void putLength(int length)
Put a length and move the current position backward.

Parameters:
length - The length to encode.

putIntegerValue

protected final void putIntegerValue(int v)
Put an integer value and move the current position backward.

Parameters:
v - The integer to encode.

putIntegerValue

protected final void putIntegerValue(long v)
Put an integer value expressed as a long.

Parameters:
v - The integer to encode.

putUnsignedLongValue

protected void putUnsignedLongValue(long v)
Put an unsigned long value and move the current position backward.

Parameters:
v - The unsigned long to encode.

putStringValue

protected final void putStringValue(byte[] s)
Put a byte string and move the current position backward.

Parameters:
s - The byte string to encode.

putOidValue

protected final void putOidValue(long[] s)
Put an oid and move the current position backward.

Parameters:
s - The oid to encode.

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.