Package org.snmp4j.smi
Class VariableBinding
java.lang.Object
org.snmp4j.smi.VariableBinding
- All Implemented Interfaces:
Serializable
,Cloneable
,BERSerializable
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 Summary
ConstructorDescriptionCreates a variable binding with a zero length OID and aNull
value.VariableBinding
(OID oid) Creates a variable binding with the supplied object instance identifier and aNull
value.VariableBinding
(OID oid, String variableText) Creates a variable binding with the supplied OID and a text value.VariableBinding
(OID oid, Variable variable) Creates a variable binding with the supplied OID and value. -
Method Summary
Modifier and TypeMethodDescriptionclone()
static VariableBinding[]
createFromOIDs
(OID[] oids) Create an array ofVariableBinding
s based on the provided OIDs.final void
decodeBER
(BERInputStream inputStream) Decodes aVariable
from anInputStream
.final void
encodeBER
(OutputStream outputStream) Encodes aVariable
to anOutputStream
.boolean
final int
Returns the length of thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).final int
Returns the length of the payload of thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).getOid()
Gets the object instance identifier of the variable binding.final int
Gets the syntax of the variable bindings value.Gets the value of the variable binding.int
hashCode()
boolean
Returns whether the variable bindings value has an exception syntax.void
Sets the object instance identifier for the variable binding.void
setVariable
(Variable variable) Sets the value of the variable binding.toString()
Gets a string representation of this variable binding using theVariableTextFormat
configured bySNMP4JSettings
.Gets a string representation of this variable binding's value using theVariableTextFormat
configured bySNMP4JSettings
.
-
Constructor Details
-
VariableBinding
public VariableBinding()Creates a variable binding with a zero length OID and aNull
value. -
VariableBinding
Creates a variable binding with the supplied object instance identifier and aNull
value.- Parameters:
oid
- the OID for the new variable binding.
-
VariableBinding
Creates a variable binding with the supplied OID and value.- Parameters:
oid
- the OID for the new variable binding (must not benull
).variable
- the value for the new variable binding (must not benull
).
-
VariableBinding
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 theVariableTextFormat
set bySNMP4JSettings.setVariableTextFormat(org.snmp4j.util.VariableTextFormat)
. The defaultSimpleVariableTextFormat
does not support this operation. To be able to use this constructor, use theSmiManager
of SNMP4J-SMI instead.- Parameters:
oid
- theOID
of the new variable binding.variableText
- the textual representation of aVariable
of the syntax defined foroid
by a MIB specification.- Throws:
ParseException
- if thevariableText
cannot be parsed oroid
's syntax is unknown.- Since:
- 2.2
-
-
Method Details
-
getOid
Gets the object instance identifier of the variable binding.- Returns:
- an
OID
.
-
setOid
Sets the object instance identifier for the variable binding.- Parameters:
oid
- an OID (must not benull
) that is cloned when added to this binding.
-
setVariable
Sets the value of the variable binding.- Parameters:
variable
- aVariable
(must not benull
) that is cloned when added to this binding.
-
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 ofNull
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 thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
getBERPayloadLength
in interfaceBERSerializable
- Returns:
- the BER encoded length of this variable.
-
getBERLength
public final int getBERLength()Description copied from interface:BERSerializable
Returns the length of thisBERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
getBERLength
in interfaceBERSerializable
- Returns:
- the BER encoded length of this variable.
-
decodeBER
Description copied from interface:BERSerializable
Decodes aVariable
from anInputStream
.- Specified by:
decodeBER
in interfaceBERSerializable
- Parameters:
inputStream
- anInputStream
containing a BER encoded byte stream.- Throws:
IOException
- if the stream could not be decoded by using BER rules.
-
encodeBER
Description copied from interface:BERSerializable
Encodes aVariable
to anOutputStream
.- Specified by:
encodeBER
in interfaceBERSerializable
- Parameters:
outputStream
- anOutputStream
.- Throws:
IOException
- if an error occurs while writing to the stream.
-
toString
Gets a string representation of this variable binding using theVariableTextFormat
configured bySNMP4JSettings
. -
toValueString
Gets a string representation of this variable binding's value using theVariableTextFormat
configured bySNMP4JSettings
.- Returns:
- a string of the form
<Variable>
. - Since:
- 1.10
-
clone
-
hashCode
public int hashCode() -
equals
-
createFromOIDs
Create an array ofVariableBinding
s based on the provided OIDs.- Parameters:
oids
- an array of OIDs (must not be null).- Returns:
- an array of
VariableBinding
s where each the n-th binding's OID is the n-th OID out ofoids
. - Since:
- 2.1
-