SNMP Stack 4_12

uk.co.westhawk.snmp.stack
Class AsnOctets

java.lang.Object
  |
  +--uk.co.westhawk.snmp.stack.AsnObject
        |
        +--uk.co.westhawk.snmp.stack.AsnOctets
All Implemented Interfaces:
SnmpConstants

public class AsnOctets
extends AsnObject

This class represents the ASN.1 Octet class. It can be used for Octets, Ip Addresses and Opaque types.

Version:
$Revision: 3.31 $ $Date: 2002/10/29 14:44:40 $
Author:
Tim Panton

Field Summary
static java.lang.String HEX_PREFIX
          The hexadecimal prefix that is used when printing a hexadecimal number in toString().
 
Fields inherited from class uk.co.westhawk.snmp.stack.AsnObject
contentsLength, debug, headerLength, isCorrect, startPos, type
 
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpConstants
ASN_APPLICATION, ASN_BIT_STR, ASN_BIT8, ASN_BOOLEAN, ASN_CONSTRUCTOR, ASN_CONTEXT, ASN_EXTENSION_ID, ASN_INTEGER, ASN_LONG_LEN, ASN_NULL, ASN_OBJECT_ID, ASN_OCTET_STR, ASN_PRIMITIVE, ASN_PRIVATE, ASN_SEQUENCE, ASN_SET, ASN_UNIVERSAL, CONS_SEQ, COUNTER, COUNTER64, GAUGE, GET_REQ_MSG, GET_RPRT_MSG, GET_RSP_MSG, GETBULK_REQ_MSG, GETNEXT_REQ_MSG, INFORM_REQ_MSG, INTEGER, IPADDRESS, NSAP_ADDRESS, NULLOBJ, OBJID, OPAQUE, SET_REQ_MSG, SNMP_ERR_AUTHORIZATIONERR, SNMP_ERR_BADVALUE, SNMP_ERR_COMMITFAILED, SNMP_ERR_DECODING_EXC, SNMP_ERR_DECODINGASN_EXC, SNMP_ERR_DECODINGPKTLNGTH_EXC, SNMP_ERR_GENERR, SNMP_ERR_INCONSISTENTNAME, SNMP_ERR_INCONSISTENTVALUE, SNMP_ERR_NOACCESS, SNMP_ERR_NOCREATION, SNMP_ERR_NOERROR, SNMP_ERR_NOSUCHNAME, SNMP_ERR_NOTWRITABLE, SNMP_ERR_READONLY, SNMP_ERR_RESOURCEUNAVAILABLE, SNMP_ERR_TOOBIG, SNMP_ERR_UNDOFAILED, SNMP_ERR_WRONGENCODING, SNMP_ERR_WRONGLENGTH, SNMP_ERR_WRONGTYPE, SNMP_ERR_WRONGVALUE, SNMP_TRAP_AUTHFAIL, SNMP_TRAP_COLDSTART, SNMP_TRAP_EGPNEIGHBORLOSS, SNMP_TRAP_ENTERPRISESPECIFIC, SNMP_TRAP_LINKDOWN, SNMP_TRAP_LINKUP, SNMP_TRAP_WARMSTART, SNMP_VAR_ENDOFMIBVIEW, SNMP_VAR_NOSUCHINSTANCE, SNMP_VAR_NOSUCHOBJECT, SNMP_VERSION_1, SNMP_VERSION_2c, SNMP_VERSION_3, STRING, TIMETICKS, TRP_REQ_MSG, TRPV2_REQ_MSG, UINTEGER32, version_id
 
Constructor Summary
AsnOctets(byte[] s)
          Constructor.
AsnOctets(byte[] s, byte t)
          Constructor to create a specific type of AsnOctets.
AsnOctets(char[] s)
          Constructor.
AsnOctets(java.net.InetAddress iad)
          Constructor to create an ASN IP Address.
AsnOctets(java.io.InputStream in, int len)
          Constructor.
AsnOctets(java.lang.String s)
          Constructor.
 
Method Summary
 boolean equals(java.lang.Object anObject)
          Compares this Octet to the specified object.
 byte[] getBytes()
          Returns the bytes.
 java.lang.String getValue()
          Returns the value.
 int hashCode()
          Returns a hash code for this Octet.
static void setHexPrefix(java.lang.String newPrefix)
          Set the global hexadecimal prefix.
 java.lang.String toDisplayString()
          Returns this object as a display string.
 java.lang.String toHex()
          Returns this object as an hexadecimal.
 java.lang.String toIpAddress()
          Returns this object as an IP Address.
 java.lang.String toString()
          Returns the string representation of the AsnOctets.
 long[] toSubOid(boolean length_implied)
          Converts this object to its corresponding sub-identifiers.
 
Methods inherited from class uk.co.westhawk.snmp.stack.AsnObject
getRespType, getRespTypeString, setDebug
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

HEX_PREFIX

public static java.lang.String HEX_PREFIX
The hexadecimal prefix that is used when printing a hexadecimal number in toString(). By default this is "0x".
Constructor Detail

AsnOctets

public AsnOctets(char[] s)
Constructor. The type of the AsnOctets defaults to ASN_OCTET_STR.
Parameters:
s - The character array representing the AsnOctets
See Also:
SnmpConstants.ASN_OCTET_STR

AsnOctets

public AsnOctets(java.lang.String s)
Constructor. The type of the AsnOctets defaults to ASN_OCTET_STR.
Parameters:
s - The string representing the AsnOctets
See Also:
SnmpConstants.ASN_OCTET_STR

AsnOctets

public AsnOctets(byte[] s)
          throws java.lang.IllegalArgumentException
Constructor. The type of the AsnOctets defaults to ASN_OCTET_STR.
Parameters:
s - The byte array representing the AsnOctets
See Also:
SnmpConstants.ASN_OCTET_STR

AsnOctets

public AsnOctets(java.net.InetAddress iad)
          throws java.lang.IllegalArgumentException
Constructor to create an ASN IP Address.
Parameters:
iad - The Inet Address representing the AsnIPAddress
See Also:
InetAddress, AsnOctets(byte[], byte)

AsnOctets

public AsnOctets(byte[] s,
                 byte t)
          throws java.lang.IllegalArgumentException
Constructor to create a specific type of AsnOctets.
Parameters:
s - The byte array representing the AsnOctets
t - The type of the AsnOctets
See Also:
SnmpConstants.ASN_OCTET_STR, SnmpConstants.IPADDRESS, SnmpConstants.OPAQUE

AsnOctets

public AsnOctets(java.io.InputStream in,
                 int len)
          throws java.io.IOException
Constructor.
Parameters:
in - The input stream from which the value should be read
len - The length of the AsnOctets
Method Detail

setHexPrefix

public static void setHexPrefix(java.lang.String newPrefix)
Set the global hexadecimal prefix. This prefix will be used in toString() when it prints out a hexadecimal number. It is not used in toHex(). The default is "0x".
See Also:
toString(), toHex(), HEX_PREFIX

getValue

public java.lang.String getValue()
Returns the value.
Returns:
The value of the AsnOctets
See Also:
toString()

getBytes

public byte[] getBytes()
Returns the bytes.
Returns:
The bytes of the AsnOctets

toString

public java.lang.String toString()
Returns the string representation of the AsnOctets.

The string will have one of the following formats:

When the type is ASN_OCTET_STR, the method tries to guess whether or not the string is printable; without the knowledge of the MIB it cannot distinguish between OctetString and DisplayString.

Overrides:
toString in class AsnObject
Returns:
The string of the AsnOctets
See Also:
HEX_PREFIX, setHexPrefix(String), toHex(), toIpAddress(), toDisplayString()

toIpAddress

public java.lang.String toIpAddress()
Returns this object as an IP Address. The format is aaa.bbb.ccc.ddd .
Returns:
The IP Address representation.
See Also:
toString()

toHex

public java.lang.String toHex()
Returns this object as an hexadecimal. It does not use the HEX_PREFIX here.
Returns:
The hex representation.
See Also:
toString()

toDisplayString

public java.lang.String toDisplayString()
Returns this object as a display string. In contrast to the method toString(), this method does not try to guess whether or not this string is a display string, it just converts it to a String.
Returns:
The string representation.
See Also:
toString()

toSubOid

public long[] toSubOid(boolean length_implied)
Converts this object to its corresponding sub-identifiers. Each octet will be encoded in a separate sub-identifier, by converting the octet into a positive long.

Use this method when building an OID when this object specifies a conceptual row. For example ipNetToMediaEntry, see RFC 2011 or SnmpCommunityEntry, see RFC 2576

The variable length_implied indicates that this MIB variable is preceded by the IMPLIED keyword. Note that the IMPLIED keyword can only be present for an object having a variable-length syntax (e.g., variable-length strings or object identifier-valued objects). Further, the IMPLIED keyword can only be associated with the last object in the INDEX clause. Finally, the IMPLIED keyword may not be used on a variable-length string object if that string might have a value of zero-length.

If the length is implied, no extra sub-identifier will be created to indicate its length. If the length is not implied, the first sub-identifier will be the length of the Octet.

If this object is of type IPADDRESS, length_implied should be false.

The mapping of the INDEX clause is explained in RFC 2578, section 7.7.

Parameters:
length_implied - Indicates if the length of this octet is implied.
See Also:
AsnObjectId.add(long[])

equals

public boolean equals(java.lang.Object anObject)
Compares this Octet to the specified object. The result is true if and only if the argument is not null and is a AsnOctets object that represents the same sequence of octets as this object.
Overrides:
equals in class java.lang.Object
Parameters:
anObject - the object to compare this AsnOctets against.
Returns:
true if the AsnOctets are equal; false otherwise.

hashCode

public int hashCode()
Returns a hash code for this Octet. The hash code for a AsnOctets object is computed as
 s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
 
using int arithmetic, where s[i] is the ith character of the Octet, n is the length of the Octet, and ^ indicates exponentiation. (The hash value of the empty Octet is zero.)
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

SNMP Stack 4_12