public class OctetString extends AbstractVariable implements AssignableFromByteArray, AssignableFromString
OctetString class represents the SMI type OCTET STRING.SMISYNTAXES_PROPERTIES| Constructor and Description |
|---|
OctetString()
Creates a zero length octet string.
|
OctetString(byte[] rawValue)
Creates an octet string from an byte array.
|
OctetString(byte[] rawValue,
int offset,
int length)
Creates an octet string from an byte array.
|
OctetString(OctetString other)
Creates an octet string from another OctetString by cloning its value.
|
OctetString(String stringValue)
Creates an octet string from a java string.
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(byte b)
Appends a single byte to this octet string.
|
void |
append(byte[] bytes)
Appends an array of bytes to this octet string.
|
void |
append(OctetString octetString)
Appends an octet string.
|
void |
append(String string)
Appends the supplied string to this
OctetString. |
void |
clear()
Sets the value of the octet string to a zero length string.
|
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) |
boolean |
equalsValue(byte[] v)
Checks if the value of this OctetString equals the argument.
|
static OctetString |
fromByteArray(byte[] value)
Creates an
OctetString from an byte array. |
static OctetString |
fromHexString(String hexString) |
static OctetString |
fromHexString(String hexString,
char delimiter) |
static OctetString |
fromHexStringPairs(String hexString)
Create an OctetString from a hexadecimal string of 2-byte pairs without
delimiter.
|
static OctetString |
fromString(String string,
char delimiter,
int radix) |
static OctetString |
fromString(String string,
int radix)
Creates an OctetString from a string represantation in the specified
radix.
|
void |
fromSubIndex(OID subIndex,
boolean impliedLength)
Sets the value of this
Variable from the supplied (sub-)index. |
byte |
get(int index)
Gets the byte at the specified index.
|
int |
getBERLength()
Returns the length of this
Variable in bytes when encoded
according to the Basic Encoding Rules (BER). |
int |
getBERPayloadLength()
Returns the length of the payload of this
BERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER). |
int |
getSyntax()
Gets the ASN.1 syntax identifier value of this SNMP variable.
|
byte[] |
getValue() |
int |
hashCode() |
boolean |
isPrintable()
Determines whether this octet string contains non ISO control characters
only.
|
int |
length()
Gets the length of the byte string.
|
OctetString |
mask(OctetString mask)
Returns a copy of this OctetString where each bit not set in the supplied
mask zeros the corresponding bit in the returned OctetString.
|
void |
set(int index,
byte b)
Sets the byte value at the specified index.
|
void |
setValue(byte[] value)
Sets the value of this object from the supplied byte array.
|
void |
setValue(String value) |
static Collection<OctetString> |
split(OctetString octetString,
OctetString delimOctets)
Splits an
OctetString using a set of delimiter characters
similar to how a StringTokenizer would do it. |
boolean |
startsWith(OctetString prefix)
Tests if this octet string starts with the specified prefix.
|
OctetString |
substring(int beginIndex,
int endIndex)
Returns a new string that is a substring of this string.
|
String |
toASCII(char placeholder)
Formats the content into a ASCII string.
|
byte[] |
toByteArray()
Returns the value of this object as a byte array.
|
String |
toHexString() |
String |
toHexString(char separator) |
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.
|
String |
toString(char separator,
int radix) |
String |
toString(int radix)
Returns a string representation of this octet string in the radix
specified.
|
OID |
toSubIndex(boolean impliedLength)
Converts the value of this
Variable to a (sub-)index
value. |
createFromBER, createFromSyntax, equal, getSyntaxFromString, getSyntaxString, getSyntaxString, isDynamic, isExceptionpublic OctetString()
public OctetString(byte[] rawValue)
rawValue - an array of bytes.public OctetString(byte[] rawValue,
int offset,
int length)
rawValue - an array of bytes.offset - the position (zero based) of the first byte to be copied from
rawValueinto the new OctetSring.length - the number of bytes to be copied.public OctetString(String stringValue)
stringValue - a Java string.public OctetString(OctetString other)
other - an OctetString instance.public void append(byte b)
b - a byte value.public void append(byte[] bytes)
bytes - an array of bytes.public void append(OctetString octetString)
octetString - an OctetString to append to this octet string.public void append(String string)
OctetString. Calling this
method is identical to append(string.getBytes()).string - a String instance.public void clear()
public void encodeBER(OutputStream outputStream) throws IOException
AbstractVariableVariable to an OutputStream.encodeBER in interface BERSerializableencodeBER in class AbstractVariableoutputStream - an OutputStream.IOException - if an error occurs while writing to the stream.public void decodeBER(BERInputStream inputStream) throws IOException
AbstractVariableVariable from an InputStream.decodeBER in interface BERSerializabledecodeBER in class AbstractVariableinputStream - an InputStream containing a BER encoded byte stream.IOException - if the stream could not be decoded by using BER rules.public int getBERLength()
AbstractVariableVariable in bytes when encoded
according to the Basic Encoding Rules (BER).getBERLength in interface BERSerializablegetBERLength in class AbstractVariablepublic int getSyntax()
AbstractVariablegetSyntax in interface VariablegetSyntax in class AbstractVariablepublic final byte get(int index)
index - a zero-based index into the octet string.ArrayIndexOutOfBoundsException - if index < 0 or > length().public final void set(int index,
byte b)
index - an index value greater or equal 0 and less than length().b - the byte value to set.public int hashCode()
hashCode in interface VariablehashCode in class AbstractVariablepublic boolean equals(Object o)
equals in interface Variableequals in class AbstractVariablepublic boolean equalsValue(byte[] v)
v - the byte array to compare with this OctetStrings value member.Arrays.equals(value, (byte[])v)public int compareTo(Variable o)
compareTo in interface Comparable<Variable>compareTo in interface VariablecompareTo in class AbstractVariablepublic OctetString substring(int beginIndex, int endIndex)
beginIndex and extends to the
character at index endIndex - 1.
Thus the length of the substring is endIndex-beginIndex.beginIndex - the beginning index, inclusive.endIndex - the ending index, exclusive.public boolean startsWith(OctetString prefix)
prefix - the prefix.true if the bytes of this octet string up to the length
of prefix equal those of prefix.public boolean isPrintable()
false if this octet string contains any ISO control
characters as defined by Character.isISOControl(char)
except if these ISO control characters are all whitespace characters
as defined by Character.isWhitespace(char) and not
'\u001C'-'\u001F'.public String toString()
AbstractVariabletoString in interface VariabletoString in class AbstractVariablepublic String toHexString()
public String toHexString(char separator)
public static OctetString fromHexString(String hexString)
public static OctetString fromHexString(String hexString, char delimiter)
public static OctetString fromString(String string, char delimiter, int radix)
public static OctetString fromHexStringPairs(String hexString)
hexString - a string of characters a-f,A-F,0-9 with length 2*b, where b is the length
of the string in bytes.hexString.length()/2.public static OctetString fromString(String string, int radix)
string - the string representation of an octet string.radix - the radix of the string represantion.public String toString(char separator, int radix)
public String toString(int radix)
round(log(256)/log(radix)) digits.radix - the radix to use in the string representation.public String toASCII(char placeholder)
placeholder - a placeholder character, for example '.'.public void setValue(String value)
setValue in interface AssignableFromStringpublic void setValue(byte[] value)
AssignableFromByteArraysetValue in interface AssignableFromByteArrayvalue - a byte array.public byte[] getValue()
public final int length()
public Object clone()
Variableclone in interface Variableclone in class AbstractVariableVariable with the same value.public int getBERPayloadLength()
BERSerializable
object in bytes when encoded according to the Basic Encoding Rules (BER).getBERPayloadLength in interface BERSerializablegetBERPayloadLength in class AbstractVariablepublic int toInt()
AbstractVariabletoInt in interface VariabletoInt in class AbstractVariablepublic long toLong()
AbstractVariabletoLong in interface VariabletoLong in class AbstractVariablepublic OctetString mask(OctetString mask)
mask - a mask where the n-th bit corresponds to the n-th bit in the returned
OctetString.public OID toSubIndex(boolean impliedLength)
AbstractVariableVariable to a (sub-)index
value.toSubIndex in interface VariabletoSubIndex in class AbstractVariableimpliedLength - 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)
AbstractVariableVariable from the supplied (sub-)index.fromSubIndex in interface VariablefromSubIndex in class AbstractVariablesubIndex - 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 static Collection<OctetString> split(OctetString octetString, OctetString delimOctets)
OctetString using a set of delimiter characters
similar to how a StringTokenizer would do it.octetString - the input string to tokenize.delimOctets - a set of delimiter octets.public static OctetString fromByteArray(byte[] value)
OctetString from an byte array.value - a byte array that is copied into the value of the created
OctetString or null.null if value
is null.public byte[] toByteArray()
AssignableFromByteArraytoByteArray in interface AssignableFromByteArrayCopyright © 2016 SNMP4J.org. All Rights Reserved.