Class SnmpIPAddress

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

    public class SnmpIPAddress
    extends SnmpOctetString

    This SnmpIPAddress is used to extend the SNMP Octet String SMI class. This is normally used to transmit IP Addresses with a length of 4 bytes.

    Most of the management of the data is handled by the base class.

    Author:
    Brian Weaver
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte ASNTYPE
      Defines the ASN.1 type for this object.
    • Constructor Summary

      Constructors 
      Constructor Description
      SnmpIPAddress()
      Constructs a default object with a length of zero.
      SnmpIPAddress​(byte[] data)
      Constructs an Application String with the passed data.
      SnmpIPAddress​(java.lang.String inetAddr)
      Constructs a new instance of the class with the IP address of the evaluated argument.
      SnmpIPAddress​(java.net.InetAddress inetAddr)
      Constructs a new instance of the class with the IP Address recovered from the passed address object.
      SnmpIPAddress​(SnmpIPAddress second)
      Copy constructor.
      SnmpIPAddress​(SnmpOctetString second)
      Copy constructor based on the base class.
    • Field Detail

      • ASNTYPE

        public static final byte ASNTYPE
        Defines the ASN.1 type for this object.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SnmpIPAddress

        public SnmpIPAddress()
        Constructs a default object with a length of zero. See the super class constructor for more details.
      • SnmpIPAddress

        public SnmpIPAddress​(byte[] data)
        Constructs an Application String with the passed data. The data is managed by the base class.
        Parameters:
        data - The application string to manage (UTF-8)
        Throws:
        java.security.InvalidParameterException - Thrown if the passed buffer is not exactly 4 octets in size.
      • SnmpIPAddress

        public SnmpIPAddress​(SnmpIPAddress second)
        Copy constructor. Constructs a duplicate object based on the passed application string object.
        Parameters:
        second - The object to copy.
      • SnmpIPAddress

        public SnmpIPAddress​(SnmpOctetString second)
        Copy constructor based on the base class.
        Parameters:
        second - The object to copy
        Throws:
        java.security.InvalidParameterException - Thrown if the passed buffer is not exactly 4 octets in size.
      • SnmpIPAddress

        public SnmpIPAddress​(java.net.InetAddress inetAddr)
        Constructs a new instance of the class with the IP Address recovered from the passed address object.
        Parameters:
        inetAddr - The internet address instance that contains the IP Address.
      • SnmpIPAddress

        public SnmpIPAddress​(java.lang.String inetAddr)
                      throws SnmpBadConversionException
        Constructs a new instance of the class with the IP address of the evaluated argument. The argument is evaluated by the InetAddressclass and the returned address is encoded in this instance.
        Parameters:
        inetAddr - The string encoded IP Address to encapsulate.
        Throws:
        SnmpBadConversionException - Thrown if the string address cannot be converted to an IP Address.
    • Method Detail

      • typeId

        public byte typeId()
        Returns the ASN.1 type for this object.
        Specified by:
        typeId in interface SnmpSyntax
        Overrides:
        typeId in class SnmpOctetString
        Returns:
        The ASN.1 value for this object.
      • clone

        public java.lang.Object clone()
        Create a new object that is a duplicate of the current object.
        Overrides:
        clone in class SnmpOctetString
        Returns:
        A newly created duplicate object.
      • 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.

        If the buffer is not valid according to the SNMP SMI then an exception is thrown and the object is not modified.

        Overrides:
        setString in class SnmpOctetString
        Parameters:
        data - The new octet string data.
        Throws:
        java.security.InvalidParameterException - Thrown if the passed buffer is not valid against the SMI definition.
      • 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.

        If the buffer is not valid according to the SNMP SMI then an exception is thrown and the object is not modified.

        Overrides:
        setString in class SnmpOctetString
        Parameters:
        data - The new octet string data.
        Throws:
        java.security.InvalidParameterException - Thrown if the passed buffer is not valid against the SMI definition.
        See Also:
        String.getBytes()
      • 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
        Overrides:
        decodeASN in class SnmpOctetString
        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.
      • convertToIpAddress

        public java.net.InetAddress convertToIpAddress()
        Converts the current Application String to an IPv4Address object. If the length is not four bytes in length or an error occurs during the conversion then an exception is thrown.
        Returns:
        The IPv4Address converted from the application string
        Throws:
        java.lang.RuntimeException - Thrown if the length of the string is invalid. Must be equal to four.
      • toString

        public java.lang.String toString()
        Returns the application string as a IPv4 dotted decimal address
        Overrides:
        toString in class SnmpOctetString
      • toInetAddress

        public static java.net.InetAddress toInetAddress​(SnmpIPAddress val)