Module org.snmp4j

Class VariableBinding

java.lang.Object
org.snmp4j.smi.VariableBinding
All Implemented Interfaces:
Serializable, Cloneable, BERSerializable

public class VariableBinding extends Object implements Serializable, BERSerializable, Cloneable
A VariableBinding is an association of a object instance identifier (OID) and the instance's value (Variable).
Version:
1.9
Author:
Frank Fock
See Also:
  • Constructor Details

    • VariableBinding

      public VariableBinding()
      Creates a variable binding with a zero length OID and a Null value.
    • VariableBinding

      public VariableBinding(OID oid)
      Creates a variable binding with the supplied object instance identifier and a Null value.
      Parameters:
      oid - the OID for the new variable binding.
    • VariableBinding

      public VariableBinding(OID oid, Variable variable)
      Creates a variable binding with the supplied OID and value.
      Parameters:
      oid - the OID for the new variable binding (must not be null).
      variable - the value for the new variable binding (must not be null).
    • VariableBinding

      public VariableBinding(OID oid, String variableText) throws ParseException
      Creates a variable binding with the supplied OID and a text value. The text value is parsed based on MIB information to a Variable using the VariableTextFormat set by SNMP4JSettings.setVariableTextFormat(org.snmp4j.util.VariableTextFormat). The default SimpleVariableTextFormat does not support this operation. To be able to use this constructor, register the SmiManager of SNMP4J-SMI instead as VariableTextFormat instead.
      Parameters:
      oid - the OID of the new variable binding.
      variableText - the textual representation of a Variable of the syntax defined for oid by a MIB specification.
      Throws:
      ParseException - if the variableText cannot be parsed or oid's syntax is unknown.
      Since:
      2.2
  • Method Details

    • getOid

      public OID getOid()
      Gets the object instance identifier of the variable binding.
      Returns:
      an OID.
    • setOid

      public void setOid(OID oid)
      Sets the object instance identifier for the variable binding.
      Parameters:
      oid - an OID (must not be null) that is cloned when added to this binding.
    • setVariable

      public void setVariable(Variable variable)
      Sets the value of the variable binding.
      Parameters:
      variable - a Variable (must not be null) that is cloned when added to this binding.
    • getVariable

      public Variable getVariable()
      Gets the value of the variable binding.
      Returns:
      a Variable instance.
    • getSyntax

      public final int getSyntax()
      Gets the syntax of the variable bindings value.
      Returns:
      a SMI syntax identifier (see SMIConstants).
    • isException

      public boolean isException()
      Returns whether the variable bindings value has an exception syntax.
      Returns:
      true if the syntax of this variable is an instance of Null and its syntax equals one of the following:
      See Also:
    • getBERPayloadLength

      public final int getBERPayloadLength()
      Description copied from interface: BERSerializable
      Returns the length of the payload of this BERSerializable object in bytes when encoded according to the Basic Encoding Rules (BER).
      Specified by:
      getBERPayloadLength in interface BERSerializable
      Returns:
      the BER encoded length of this variable.
    • getBERLength

      public final int getBERLength()
      Description copied from interface: BERSerializable
      Returns the length of this BERSerializable object in bytes when encoded according to the Basic Encoding Rules (BER).
      Specified by:
      getBERLength in interface BERSerializable
      Returns:
      the BER encoded length of this variable.
    • decodeBER

      public final void decodeBER(BERInputStream inputStream) throws IOException
      Description copied from interface: BERSerializable
      Decodes a Variable from an InputStream.
      Specified by:
      decodeBER in interface BERSerializable
      Parameters:
      inputStream - an InputStream containing a BER encoded byte stream.
      Throws:
      IOException - if the stream could not be decoded by using BER rules.
    • encodeBER

      public final void encodeBER(OutputStream outputStream) throws IOException
      Description copied from interface: BERSerializable
      Encodes a Variable to an OutputStream.
      Specified by:
      encodeBER in interface BERSerializable
      Parameters:
      outputStream - an OutputStream.
      Throws:
      IOException - if an error occurs while writing to the stream.
    • toString

      public String toString()
      Gets a string representation of this variable binding using the VariableTextFormat configured by SNMP4JSettings.
      Overrides:
      toString in class Object
      Returns:
      a string of the form <OID> = <Variable>.
    • toValueString

      public String toValueString()
      Gets a string representation of this variable binding's value using the VariableTextFormat configured by SNMP4JSettings.
      Returns:
      a string of the form <Variable>.
      Since:
      1.10
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • createFromOIDs

      public static VariableBinding[] createFromOIDs(OID[] oids)
      Create an array of VariableBindings based on the provided OIDs.
      Parameters:
      oids - an array of OIDs (must not be null).
      Returns:
      an array of VariableBindings where each the n-th binding's OID is the n-th OID out of oids.
      Since:
      2.1