public class IpAddress extends SMIAddress implements AssignableFromByteArray
IpAddress
class represents an IPv4 address SNMP variable.Modifier and Type | Field and Description |
---|---|
static InetAddress |
ANY_IPADDRESS |
SMISYNTAXES_PROPERTIES
Constructor and Description |
---|
IpAddress()
Creates a
0.0.0.0 IP address. |
IpAddress(byte[] addressBytes)
Create an IP address from a raw IP address.
|
IpAddress(InetAddress address)
Creates an IP address from an
InetAddress |
IpAddress(String address)
Create an IP address from an address string.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Clones this variable.
|
int |
compareTo(Variable o) |
void |
decodeBER(BERInputStream inputStream)
Decodes a
Variable from an InputStream . |
void |
encodeBER(OutputStream outputStream)
Encodes a
Variable to an OutputStream . |
boolean |
equals(Object o) |
void |
fromSubIndex(OID subIndex,
boolean impliedLength)
Sets the value of this
Variable from the supplied (sub-)index. |
int |
getBERLength()
Returns the length of this
Variable in bytes when encoded
according to the Basic Encoding Rules (BER). |
InetAddress |
getInetAddress() |
int |
getSyntax()
Gets the ASN.1 syntax identifier value of this SNMP variable.
|
int |
hashCode() |
boolean |
isValid()
Checks whether this
Address is a valid transport address. |
static Address |
parse(String address)
Parses an IP address string and returns the corresponding
IpAddress instance. |
boolean |
parseAddress(String address)
Parses the address from the supplied string representation.
|
void |
setAddress(byte[] rawValue) |
void |
setInetAddress(InetAddress inetAddress) |
void |
setValue(byte[] value)
Sets the value of this object from the supplied byte array.
|
void |
setValue(String value)
Sets the address value from the supplied String.
|
byte[] |
toByteArray()
Returns the value of this object as a byte array.
|
int |
toInt()
Returns an integer representation of this variable if
such a representation exists.
|
long |
toLong()
Returns a long representation of this variable if
such a representation exists.
|
String |
toString()
Gets a string representation of the variable.
|
OID |
toSubIndex(boolean impliedLength)
Converts the value of this
Variable to a (sub-)index
value. |
createFromBER, createFromSyntax, equal, getBERPayloadLength, getSyntaxFromString, getSyntaxString, getSyntaxString, isDynamic, isException
public static final InetAddress ANY_IPADDRESS
public IpAddress()
0.0.0.0
IP address.public IpAddress(InetAddress address)
InetAddress
address
- an InetAddress
instance (must not necessarily be a IPv4
address).public IpAddress(String address)
address
- an IP address String.Address.parseAddress(String address)
public IpAddress(byte[] addressBytes)
addressBytes
- the raw IP address in network byte order.public int getSyntax()
AbstractVariable
getSyntax
in interface Variable
getSyntax
in class AbstractVariable
public boolean isValid()
Address
Address
is a valid transport address.public String toString()
AbstractVariable
toString
in interface Variable
toString
in class AbstractVariable
public int hashCode()
hashCode
in interface Variable
hashCode
in class AbstractVariable
public static Address parse(String address)
IpAddress
instance.address
- an IP address string which may be a host name or a numerical IP address.IpAddress
instance or null
if
address
cannot not be parsed.Address.parseAddress(String address)
public boolean parseAddress(String address)
Address
parseAddress
in interface Address
address
- a String representation of this address.true
if address
could be successfully
parsed and has been assigned to this address object, false
otherwise.public int compareTo(Variable o)
compareTo
in interface Comparable<Variable>
compareTo
in interface Variable
compareTo
in class AbstractVariable
public boolean equals(Object o)
equals
in interface Variable
equals
in class AbstractVariable
public void decodeBER(BERInputStream inputStream) throws IOException
AbstractVariable
Variable
from an InputStream
.decodeBER
in interface BERSerializable
decodeBER
in class AbstractVariable
inputStream
- an InputStream
containing a BER encoded byte stream.IOException
- if the stream could not be decoded by using BER rules.public void encodeBER(OutputStream outputStream) throws IOException
AbstractVariable
Variable
to an OutputStream
.encodeBER
in interface BERSerializable
encodeBER
in class AbstractVariable
outputStream
- an OutputStream
.IOException
- if an error occurs while writing to the stream.public int getBERLength()
AbstractVariable
Variable
in bytes when encoded
according to the Basic Encoding Rules (BER).getBERLength
in interface BERSerializable
getBERLength
in class AbstractVariable
public void setAddress(byte[] rawValue) throws UnknownHostException
UnknownHostException
public void setInetAddress(InetAddress inetAddress)
public InetAddress getInetAddress()
public Object clone()
Variable
clone
in interface Variable
clone
in class AbstractVariable
Variable
with the same value.public int toInt()
AbstractVariable
toInt
in interface Variable
toInt
in class AbstractVariable
public long toLong()
AbstractVariable
toLong
in interface Variable
toLong
in class AbstractVariable
public OID toSubIndex(boolean impliedLength)
AbstractVariable
Variable
to a (sub-)index
value.toSubIndex
in interface Variable
toSubIndex
in class AbstractVariable
impliedLength
- specifies if the sub-index has an implied length. This parameter applies
to variable length variables only (e.g. OctetString
and
OID
). For other variables it has no effect.public void fromSubIndex(OID subIndex, boolean impliedLength)
AbstractVariable
Variable
from the supplied (sub-)index.fromSubIndex
in interface Variable
fromSubIndex
in class AbstractVariable
subIndex
- the sub-index OID.impliedLength
- specifies if the sub-index has an implied length. This parameter applies
to variable length variables only (e.g. OctetString
and
OID
). For other variables it has no effect.public void setValue(String value)
Address
IllegalArgumentException
runtime exception is thrown.setValue
in interface Address
setValue
in interface AssignableFromString
value
- an address String.public void setValue(byte[] value)
AssignableFromByteArray
setValue
in interface AssignableFromByteArray
value
- a byte array.public byte[] toByteArray()
AssignableFromByteArray
toByteArray
in interface AssignableFromByteArray
Copyright © 2013 SNMP4J.org. All rights reserved.