Class SnmpOctetString

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte ASNTYPE
      The ASN.1 value for the OCTET STRING type.
    • 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​(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 Object clone()
        Creates a duplicate copy of the object and returns it to the caller.
        Overrides:
        clone in class Object
        Returns:
        A newly constructed copy of self
      • toString

        public 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 Object
      • toDisplayString

        public static 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object