Class AsnOctets
- All Implemented Interfaces:
SnmpConstants
Note, the SNMP representation of IPv4 and IPv6 is different:
- IPv4: IPADDRESS (or ASN_OCTET_STR, see rfc 4001)
- IPv6: ASN_OCTET_STR
- Version:
- $Revision: 3.39 $ $Date: 2006/03/23 14:54:10 $
- Author:
- Tim Panton
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic SimpleDateFormat
The object that is used in toCalendar() to format the calendar representation of the Octets according to the DateAndTime text convension.static String
The hexadecimal prefix that is used when printing a hexadecimal number in toString().static AsnOctetsPrintableFace
The default AsnOctetsPrintableFace object.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, OBSOLETED_RFC1442_UINTEGER32, OPAQUE, SET_REQ_MSG, SMI_V2_UINTEGER32, 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
-
Constructor Summary
ConstructorsConstructorDescriptionAsnOctets
(byte[] s) Constructor.AsnOctets
(byte[] s, byte t) Constructor to create a specific type of AsnOctets.AsnOctets
(char[] s) Constructor.AsnOctets
(InputStream in, int len) Constructor.Constructor.AsnOctets
(Inet4Address iad, byte t) Constructor to create an ASN IPv4 Address.AsnOctets
(InetAddress iad) Constructor to create an ASN IP Address.Constructor for DateAndTime text convension. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compares this Octet to the specified object.byte[]
getBytes()
Returns the bytes.Returns the Octets as Calendar according to the DateAndTime text convension.Returns this Octet as an IP Address.getValue()
Returns the String value.int
hashCode()
Returns a hash code for this Octet.static void
setHexPrefix
(String newPrefix) Sets the global hexadecimal prefix.static void
Sets the global AsnOctetsPrintableFace printableObject.Returns the String representation according to the DateAndTime convension.Returns this Octet as a display string (text convension).toHex()
Returns this Octet as an hexadecimal String, without any prefix.Returns this Octet as an international display string (text convension).As toInternationalDisplayString(), but this methods will use this specific, one-off AsnOctetsPrintableFace object.Returns this Octet as an IP Address string.toString()
Returns the string representation of the AsnOctets.As toString(), but this methods will use this specific, one-off AsnOctetsPrintableFace object.long[]
toSubOid
(boolean length_implied) Converts this Octet to its corresponding sub-identifiers.Methods inherited from class uk.co.westhawk.snmp.stack.AsnObject
getRespType, getRespTypeString, setDebug
-
Field Details
-
HEX_PREFIX
The hexadecimal prefix that is used when printing a hexadecimal number in toString(). By default this is "0x". -
CALFORMAT
The object that is used in toCalendar() to format the calendar representation of the Octets according to the DateAndTime text convension. The pattern is "yyyy-M-d,HH:mm:ss.SS,z".- See Also:
-
printableObject
The default AsnOctetsPrintableFace object.
-
-
Constructor Details
-
AsnOctets
Constructor. The type of the AsnOctets defaults to ASN_OCTET_STR.- Parameters:
s
- The byte array representing the AsnOctets- Throws:
IllegalArgumentException
- See Also:
-
AsnOctets
Constructor to create a specific type of AsnOctets.- Parameters:
s
- The byte array representing the AsnOctetst
- The type of the AsnOctets- Throws:
IllegalArgumentException
- See Also:
-
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:
-
AsnOctets
Constructor. The type of the AsnOctets defaults to ASN_OCTET_STR.- Parameters:
s
- The string representing the AsnOctets- See Also:
-
AsnOctets
Constructor to create an ASN IP Address. If the address represents an IPv4 address, the asn type will be set to IPADDRESS. If it represents an IPv6 address, the asn type will be set to ASN_OCTET_STR.
Note, the SNMP representation of IPv4 and IPv6 is different:- IPv4: IPADDRESS (or ASN_OCTET_STR, see rfc 4001)
- IPv6: ASN_OCTET_STR
- Parameters:
iad
- The Inet Address- Throws:
IllegalArgumentException
- See Also:
-
AsnOctets
Constructor to create an ASN IPv4 Address. If the address is an IPv4 address, it can either be represented by IPADDRESS or as ASN_OCTET_STR. See also IPV6-TC, SNMPv2-PDU, INET-ADDRESS-MIB.- Parameters:
iad
- The IPv4 Inet Addresst
- The type of the AsnOctets- Throws:
IllegalArgumentException
- Since:
- 4_14
- See Also:
-
AsnOctets
Constructor for DateAndTime text convension. See SNMPv2-TCfield octets contents range ----- ------ -------- ----- 1 1-2 year* 0..65536 2 3 month 1..12 3 4 day 1..31 4 5 hour 0..23 5 6 minutes 0..59 6 7 seconds 0..60 (use 60 for leap-second) 7 8 deci-seconds 0..9 8 9 direction from UTC '+' / '-' 9 10 hours from UTC* 0..13 10 11 minutes from UTC 0..59 SYNTAX OCTET STRING (SIZE (8 | 11))
- Since:
- 4_14
-
AsnOctets
Constructor.- Parameters:
in
- The input stream from which the value should be readlen
- The length of the AsnOctets- Throws:
IOException
-
-
Method Details
-
setHexPrefix
Sets 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:
-
setPrintable
Sets the global AsnOctetsPrintableFace printableObject. This object will be used in the toString() and the toInternationalDisplayString() methods.- Since:
- 4_14
- See Also:
-
getValue
Returns the String value. Calls toString().- Returns:
- The value of the AsnOctets
- See Also:
-
getBytes
public byte[] getBytes()Returns the bytes. This returns a copy of the internal byte array.- Returns:
- The bytes of the AsnOctets
-
toString
Returns the string representation of the AsnOctets.The string will have one of the following formats:
- if this class represents an IP Address (v4), it will call toIpAddress()
- <prefix>aa[:bb]*, if this class represents a non-printable string or has type OPAQUE. The output will be in hexadecimal numbers (see toHex()). It will be prefixed according to the hex. prefix value
- a printable string, if this class seems printable
When the type is ASN_OCTET_STR, this method uses the AsnOctetsPrintableFace.isPrintable() to determine whether or not the string is printable. If it is printable, it will use AsnOctetsPrintableFace.toInternationalDisplayString() to transform the Octets to a String.
Note, the SNMP representation of IPv4 and IPv6 is different:- IPv4: IPADDRESS (or ASN_OCTET_STR, see rfc 4001)
- IPv6: ASN_OCTET_STR
-
toString
As toString(), but this methods will use this specific, one-off AsnOctetsPrintableFace object.- Since:
- 4_14
- See Also:
-
toIpAddress
Returns this Octet as an IP Address string. The format is aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6). Note, the SNMP representation of IPv4 and IPv6 is different:- IPv4: IPADDRESS (or ASN_OCTET_STR, see rfc 4001)
- IPv6: ASN_OCTET_STR
- Returns:
- The IP Address representation.
- See Also:
-
getIpAddress
Returns this Octet as an IP Address. Note, the SNMP representation of IPv4 and IPv6 is different:- IPv4: IPADDRESS (or ASN_OCTET_STR, see rfc 4001)
- IPv6: ASN_OCTET_STR
- Returns:
- The IP Address representation.
- Throws:
RuntimeException
- Thrown when the Octets does not represent an InetAddress or when the method internally throws an java.net.UnknownHostException- Since:
- 4_14
- See Also:
-
toHex
Returns this Octet as an hexadecimal String, without any prefix.- Returns:
- The hex representation.
- See Also:
-
toDisplayString
Returns this Octet as a display string (text convension). In contrast to the method toString(), this method does not try to guess whether or not this string is printable, it just converts it to a String, using "US-ASCII" character set.DisplayString represents textual information taken from the NVT ASCII character set, as defined in pages 4, 10-11 of RFC 854. Any object defined using this syntax may not exceed 255 characters in length. Basicly it is US-ASCII with some changes.
- Returns:
- The string representation.
- See Also:
-
toInternationalDisplayString
Returns this Octet as an international display string (text convension). It calls AsnOctetsPrintableFace.toInternationalDisplayString(). See HOST-RESOURCES-MIB- Since:
- 4_14
- See Also:
-
toInternationalDisplayString
As toInternationalDisplayString(), but this methods will use this specific, one-off AsnOctetsPrintableFace object.- Since:
- 4_14
- See Also:
-
toCalendar
Returns the String representation according to the DateAndTime convension. This string it returns is not exactly the same as the DISPLAY-HINT indicates. See SNMPv2-TC- Throws:
RuntimeException
- Thrown when the number of Octets does not represent the DateAndTime length.- Since:
- 4_14
- See Also:
-
getCalendar
Returns the Octets as Calendar according to the DateAndTime text convension. You can only call this method if the syntax of this Octet is the DateAndTime text convension.- Throws:
RuntimeException
- Thrown when the number of Octets does not represent the DateAndTime length.- Since:
- 4_14
- See Also:
-
toSubOid
public long[] toSubOid(boolean length_implied) Converts this Octet 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 Octet specifies a conceptual row. For example ipNetToMediaEntry, see IP-MIB or SnmpCommunityEntry, see SNMP-COMMUNITY-MIB
The variable
length_implied
indicates that this MIB variable is preceded by the IMPLIED keyword:- The IMPLIED keyword can only be present for an Octet having a variable-length syntax (e.g., variable-length strings or object identifier-valued objects).
- The IMPLIED keyword can only be associated with the last object in the INDEX clause.
- The IMPLIED keyword may not be used on a variable-length string Octet 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 Octet is of type IPADDRESS, length_implied should be false.
The mapping of the INDEX clause is explained in SNMPv2-SMI, section 7.7.
- Parameters:
length_implied
- Indicates if the length of this octet is implied.- See Also:
-
equals
Compares this Octet to the specified object. The result istrue
if and only if the argument is notnull
and is anAsnOctets
object that represents the same sequence of octets as this Octet. -
hashCode
public int hashCode()Returns a hash code for this Octet. The hash code for aAsnOctets
object is computed ass[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
int
arithmetic, wheres[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.)
-