Class SnmpOctetString

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, 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.
    Author:
    Brian Weaver
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte ASNTYPE
      The ASN.1 value for the OCTET STRING type.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      boolean equals​(java.lang.Object obj)  
      int getLength()
      Returns the internal length of the octet string.
      byte[] getString()
      Returns a reference to the internal object string.
      int hashCode()  
      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().
      static java.lang.String toDisplayString​(SnmpOctetString octetString)
      This method takes an SnmpOctetString and replaces any unprintable characters with ASCII period ('.') and returns the resulting character string.
      static java.lang.String toHexString​(SnmpOctetString ostr)  
      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

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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.
        Overrides:
        clone in class java.lang.Object
        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.
        Overrides:
        toString in class java.lang.Object
      • toDisplayString

        public static java.lang.String toDisplayString​(SnmpOctetString octetString)
        This method takes an SnmpOctetString and replaces any unprintable characters with ASCII period ('.') and returns the resulting character string. Special case in which the supplied SnmpOctetString consists of a single ASCII Null byte is also handled. In this special case an empty string is returned. NOTE: A character is considered unprintable if its decimal value falls outside of the range: 32 - 126.
        Parameters:
        octetString - SnmpOctetString from which to generate the String
        Returns:
        a Java String object created from the octet string's byte array.
      • toHexString

        public static java.lang.String toHexString​(SnmpOctetString ostr)
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object