com.adventnet.snmp.snmp2
Class SnmpString

java.lang.Object
  extended by com.adventnet.snmp.snmp2.SnmpVar
      extended by com.adventnet.snmp.snmp2.SnmpString
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
SnmpBits, SnmpIpAddress, SnmpNsap, SnmpOpaque

public class SnmpString
extends SnmpVar

Class of SNMP String Variable - Sub-class of SnmpVar. This class can be used to create an SnmpVar object of type SnmpString. It also has methods to retrieve the value in different forms(eg. String, byte). Some Notes : A hex string can also be specified in the constructor of this object. To do so just enclose the string within single quotes with each byte separated by a colon. For example for 0x09a2bec3 use new SnmpString("'09:a2:be:c3'").

All the String encoding will be done based on the encoding set in the SnmpAPI. The default encoding string will be ISO8859_1 which is the standard one. To avoid any kind of problems with String encoding, one can also use the new SnmpString(byte[] b) for creating and toBytes() method for retrieving the values of SnmpVar objects. With these methods none of the String encoding routines in java is used. Instead it uses the bytes directly.

See Also:
Serialized Form

Field Summary
(package private)  byte[] byteValue
           
static java.lang.String enc
          The Standard encoding string on which all encoding will be done.
(package private) static byte[] s_emptyString
           
(package private)  java.lang.String value
           
 
Fields inherited from class com.adventnet.snmp.snmp2.SnmpVar
Type, varbindErrorVal
 
Constructor Summary
protected SnmpString()
          Constuctor to keep subclasses happy
  SnmpString(byte[] b)
          Constructs a new SnmpString with the specified byte array of octect string.
  SnmpString(java.lang.String s)
          Constructs a new SnmpString with initial value = s .
  SnmpString(java.lang.String s, java.lang.String enc)
          Constructs a new SnmpString with initial value = s and encoding enc.
 
Method Summary
(package private)  int encode(byte[] buff, int space)
          ASN encoder
 boolean equals(java.lang.Object obj)
          Returns true if both the SnmpString objects are equal.
 java.lang.String getNumericValueAsString()
          This method will throw UnsupportedOperationException since this is not a numeric data type.
 java.lang.Object getVarObject()
          Returns the value of this SnmpString object as a printable string object.
(package private) static SnmpVar newInstance(byte[] b)
          Factory method for decode
 byte[] toBytes()
          To return the value of this SnmpString object as raw bytes.
 java.lang.String toByteString()
          To convert the value of this SnmpString object to a printable HEX string.
 java.lang.String toString()
          To convert the value of this SnmpString object to a printable string
 java.lang.String toTagString()
          To convert the value of this SnmpString object to a printable string where the type is tagged before the value with a tag STRING:.
 java.lang.Object toValue()
          Returns the value of this SnmpString object as a printable string object.
 
Methods inherited from class com.adventnet.snmp.snmp2.SnmpVar
createVariable, getError, getType, getTypeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

s_emptyString

static final byte[] s_emptyString

value

java.lang.String value

byteValue

byte[] byteValue

enc

public static java.lang.String enc
The Standard encoding string on which all encoding will be done. This will refer to SnmpAPI for the encoding string.

Constructor Detail

SnmpString

protected SnmpString()
Constuctor to keep subclasses happy


SnmpString

public SnmpString(java.lang.String s)
Constructs a new SnmpString with initial value = s . The Encoding will be done on the encoding string set in SnmpAPI.ENCODING.The default is ISO8859_1.If you want to change the encoding, change the static string enc of this class or change in the SnmpAPI using setCharacterEncoding.

Parameters:
s - The string value for creating a new SnmpString object.

SnmpString

public SnmpString(java.lang.String s,
                  java.lang.String enc)
Constructs a new SnmpString with initial value = s and encoding enc. To avoid any kind of problems with String encoding, one can use the new SnmpString(byte[] b) for creating and toBytes() method for retriving the values of SnmpVar objects. With these methods none of the String encoding routines in java is used. Instead it uses the bytes directly.

Parameters:
s - The value for this SnmpString object.
enc - The string for the encoding scheme to be used.

SnmpString

public SnmpString(byte[] b)
Constructs a new SnmpString with the specified byte array of octect string. To avoid any kind of problems with String encoding, one can use this constructor for creating an SnmpVar object of type SnmpString. Similarly one can use the toBytes() method to retrive the value. With these methods none of the String encoding routines in java is used. Instead it uses the bytes directly.

Parameters:
b - The byte array of octet string
Method Detail

newInstance

static SnmpVar newInstance(byte[] b)
Factory method for decode

Parameters:
b - The bytearray return The snmp variable

getVarObject

public java.lang.Object getVarObject()
Returns the value of this SnmpString object as a printable string object. This method is the same as toValue()

Specified by:
getVarObject in class SnmpVar
Returns:
the value of SnmpString object as a printable string.

equals

public boolean equals(java.lang.Object obj)
Returns true if both the SnmpString objects are equal. This method is independent of the type of encoding that is used to create these objects.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the SnmpString object which is to be checked for equality.
Returns:
true, if both the objects are equal and false, otherwise.

toValue

public java.lang.Object toValue()
Returns the value of this SnmpString object as a printable string object. This method is the same as toString()

Specified by:
toValue in class SnmpVar
Returns:
the value of SnmpString object as a printable string.

toString

public java.lang.String toString()
To convert the value of this SnmpString object to a printable string

Specified by:
toString in class SnmpVar
Returns:
the value of SnmpString object as a printable string.

toTagString

public java.lang.String toTagString()
To convert the value of this SnmpString object to a printable string where the type is tagged before the value with a tag STRING:. For e.g if the SnmpString has the value "AdventNet", then this method will return - STRING: AdventNet.

Specified by:
toTagString in class SnmpVar
Returns:
the value of SnmpString object as a printable string where the type is tagged before the value with a Tag - STRING: .

toByteString

public java.lang.String toByteString()
To convert the value of this SnmpString object to a printable HEX string. For e.g if an array of byte of length 2 has the following values: b[0] = 0x81 and b[1] = 0xFF, and this is represented as an SnmpString object, then this method prints the HEX value as "81 FF".

Returns:
The value of this SnmpString object as a printable HEX string

toBytes

public byte[] toBytes()
To return the value of this SnmpString object as raw bytes. To avoid any kind of problems with String encoding, one can use this method to retrive the value. Similarly one can use the new SnmpString(byte[]) for creating new SnmpString object. With these methods none of the String encoding routines in java is used. Instead it uses the bytes directly.

Specified by:
toBytes in class SnmpVar
Returns:
The value of this SnmpString as byte value.

getNumericValueAsString

public java.lang.String getNumericValueAsString()
This method will throw UnsupportedOperationException since this is not a numeric data type.

Overrides:
getNumericValueAsString in class SnmpVar
Returns:
Nothing is returned since this method throws an exception.
Throws:
java.lang.UnsupportedOperationException - Since this is not a numeric data type.

encode

int encode(byte[] buff,
           int space)
     throws java.lang.ArrayIndexOutOfBoundsException
ASN encoder

Specified by:
encode in class SnmpVar
Parameters:
buff - The buffer into which the value is to be encoded
space - The number of free bytes in the buffer
Returns:
The number of free bytes in the buffer
Throws:
java.lang.ArrayIndexOutOfBoundsException - When there is insufficient space in buffer