OpenNMS API 1.2.9

## org.opennms.protocols.snmp
Class SnmpOctetString

    java.lang.Object
      org.opennms.protocols.snmp.SnmpOctetString

All Implemented Interfaces:
  java.lang.Cloneable, java.io.Serializable, SnmpSyntax

Direct Known Subclasses:
  SnmpIPAddress, SnmpOpaque

public class SnmpOctetString
extends java.lang.Object
implements SnmpSyntax, java.lang.Cloneable, java.io.Serializable

Implements the ASN1.UNIVERSAL Octet String datatype. The string is a sequence of 8-bit octet data. The format of the 8-bit characters are defined by the application.

Version:
  1.1.1.1
Author:
  Serialized Form

Field Summary
`static byte` `ASNTYPE` The ASN.1 value for the OCTET STRING type.
`private byte[]` `m_data` The actual octet string data (UTF-8)
`(package private) static long` `serialVersionUID` Required to allow evolution of serialization format.

Constructor Summary
`SnmpOctetString()` The default class constructor.
`SnmpOctetString(byte[] data)` Constructs an octet string with the inital value equal to data.
`SnmpOctetString(SnmpOctetString second)` Class copy constructor.

Method Summary
`protected void` `assumeString(byte[] data)` This can be used by a derived class to force the data contained by the octet string.
`java.lang.Object` `clone()` Creates a duplicate copy of the object and returns it to the caller.
`int` `decodeASN(byte[] buf, int offset, AsnEncoder encoder)` Decodes the ASN.1 octet string from the passed buffer.
`SnmpSyntax` `duplicate()` Creates a duplicate copy of the object and returns it to the caller.
`int` `encodeASN(byte[] buf, int offset, AsnEncoder encoder)` Encodes the ASN.1 octet string using the passed encoder and stores the results in the passed buffer.
`int` `getLength()` Returns the internal length of the octet string.
`byte[]` `getString()` Returns a reference to the internal object string.
`void` `setString(byte[] data)` Sets the internal string array so that it is identical to the passed array.
`void` `setString(java.lang.String data)` Sets the internal octet string equal to the converted stirng via the method getBytes().
`java.lang.String` `toString()` Returns a string representation of the object.
`byte` `typeId()` Returns the ASN.1 type identifier for the Octet String.

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### serialVersionUID

    static final long serialVersionUID

  Required to allow evolution of serialization format.

  See Also:
    Constant Field Values

### m_data

    private byte[] m_data

  The actual octet string data (UTF-8)

### ASNTYPE

    public static final byte ASNTYPE

  The ASN.1 value for the OCTET STRING type.

  See Also:
    Constant Field Values

Constructor Detail

### SnmpOctetString

    public SnmpOctetString()

  The default class constructor. Constructs an Octet String with a length of zero and no data.

### SnmpOctetString

    public SnmpOctetString(byte[] data)

  Constructs an octet string with the inital value equal to data. The data is actually copied so changes to the data reference do not affect the Octet string object.

Parameters:
  `data` - The data to be copied to self

### SnmpOctetString

    public SnmpOctetString(SnmpOctetString second)

  Class copy constructor. Constructs and octet string object that is a duplicate of the object second.

Parameters:
  `second` - The object to copy into self

Method Detail

### assumeString

    protected void assumeString(byte[] data)

  This can be used by a derived class to force the data contained by the octet string. The data is not duplicated, only the reference to the array is stored. No validation of data is performed at all.

  Parameters:
    `data` - The new data buffer.

### getString

    public byte[] getString()

  Returns a reference to the internal object string. Changes to this byte array WILL affect the octet string object. These changes should not be made lightly.

  Returns:
    A reference to the internal byte array.

### setString

    public void setString(byte[] data)

  Sets the internal string array so that it is identical to the passed array. The array is actually copied so that changes to data after the construction of the object are not reflected in the SnmpOctetString Object.

  Parameters:
    `data` - The new octet string data.

### setString

    public void setString(java.lang.String data)

  Sets the internal octet string equal to the converted stirng via the method getBytes(). This may cause some data corruption since the conversion is platform specific.

  Parameters:
    `data` - The new octet string data.
  See Also:
    `String.getBytes()`

### getLength

    public int getLength()

  Returns the internal length of the octet string. This method is favored over recovereing the length from the internal array. The method compensates for a null set of data and returns zero if the internal array is null.

  Returns:
    The length of the octet string.

### typeId

    public byte typeId()

  Returns the ASN.1 type identifier for the Octet String.

  Specified by:
    `typeId` in interface `SnmpSyntax`
  Returns:
    The ASN.1 identifier.

### encodeASN

    public int encodeASN(byte[] buf,
                         int offset,
                         AsnEncoder encoder)
                  throws AsnEncodingException

  Encodes the ASN.1 octet string using the passed encoder and stores the results in the passed buffer. An exception is thrown if an error occurs with the encoding of the information.

  Specified by:
    `encodeASN` in interface `SnmpSyntax`
  Parameters:
    `buf` - The buffer to write the encoded information.
    `offset` - The offset to start writing information
    `encoder` - The encoder object.
  Returns:
    The offset of the byte immediantly after the last encoded byte.
  Throws:
    `AsnEncodingException` - Thrown if the encoder finds an error in the buffer.

### decodeASN

    public int decodeASN(byte[] buf,
                         int offset,
                         AsnEncoder encoder)
                  throws AsnDecodingException

  Decodes the ASN.1 octet string from the passed buffer. If an error occurs during the decoding sequence then an AsnDecodingException is thrown by the method. The value is decoded using the AsnEncoder passed to the object.

  Specified by:
    `decodeASN` in interface `SnmpSyntax`
  Parameters:
    `buf` - The encode buffer
    `offset` - The offset byte to begin decoding
    `encoder` - The decoder object.
  Returns:
    The index of the byte immediantly after the last decoded byte of information.
  Throws:
    `AsnDecodingException` - Thrown by the encoder if an error occurs trying to decode the data buffer.

### duplicate

    public SnmpSyntax duplicate()

  Creates a duplicate copy of the object and returns it to the caller.

  Specified by:
    `duplicate` in interface `SnmpSyntax`
  Returns:
    A newly constructed copy of self

### clone

    public java.lang.Object clone()

  Creates a duplicate copy of the object and returns it to the caller.

  Returns:
    A newly constructed copy of self

### toString

    public java.lang.String toString()

  Returns a string representation of the object. If the object contains non-printable characters then the contents are printed in hexidecimal.

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.