public final class ByteString extends Object implements Comparable<ByteString>, BitField
| Modifier and Type | Field and Description |
|---|---|
static ByteString |
EMPTY
ByteString instance that models empty ByteString.
|
static ByteString[] |
EMPTY_ARRAY |
| Modifier and Type | Method and Description |
|---|---|
ByteString |
append(byte[] data)
Returns a ByteString where the given bytes are appended to this ByteString.
|
ByteString |
append(ByteString data)
Returns a ByteString where the given bytes are appended to this ByteString.
|
static byte[] |
asByteArray(ByteString byteString)
A null-safe way to convert ByteString to byte[].
|
int |
compareTo(ByteString other) |
void |
copyTo(ByteArrayOutputStream stream)
Copies the contents of this ByteString to the given stream.
|
void |
copyTo(ByteArrayOutputStream stream,
int offset,
int length)
Same as
copyTo(ByteArrayOutputStream), but allows specifying part of this ByteString
to be put to the stream. |
void |
copyTo(IBinaryWriteable stream)
|
void |
copyTo(IBinaryWriteable stream,
int offset,
int length)
Same as
copyTo(ByteArrayOutputStream, int, int), but for IBinaryWriteable, but
needs handling of IOException. |
void |
copyTo(OutputStream stream)
Same as
copyTo(ByteArrayOutputStream), but works for all OutputStream, but
needs handling of IOException. |
void |
copyTo(OutputStream stream,
int offset,
int length)
Same as
copyTo(ByteArrayOutputStream, int, int), but works for all
OutputStream, but needs handling of IOException. |
boolean |
equals(Object obj) |
static ByteString |
from(ByteArrayOutputStream stream)
Returns a
ByteString whose value matches as if
ByteArrayOutputStream.toByteArray() was called for the given stream. |
static ByteString |
fromBitSet(BitSet set)
Creates a ByteString from a
BitSet. |
static ByteString |
fromBitSet(BitSet set,
int minimumLengthInBytes)
Same as
fromBitSet(BitSet), but allows specifying a minimum length. |
static ByteString |
fromHex(String hex)
Creates a ByteString from a hex string.
|
static ByteString |
fromLong(long value)
Creates a
ByteString where the given Long (OPC UA Int64) is OPC UA Binary encoded (i.e. |
static ByteString |
fromUUID(UUID guid)
Creates a
ByteString where the given UUID is OPC UA Binary encoded (i.e. |
int |
getLength()
Return the length of this ByteString.
|
byte[] |
getValue()
Get a copy of the value of this ByteString as byte array.
|
int |
hashCode() |
boolean |
isBitSet(int position)
Is bit set in position.
|
static boolean |
isNullOrEmpty(ByteString data)
Returns true if given data is null or
EMPTY , false otherwise. |
BitSet |
toBitSet()
Returns a
BitSet with the copy of the data of this ByteString. |
String |
toHex()
Calls
CryptoUtil.toHex(byte[], int, boolean) with the value of this ByteString without
length prefix and 0 (no limit) for bytesPerRow. |
String |
toString() |
static ByteString |
valueOf(byte... byteArray)
Creates a ByteString from a byte array (will copy).
|
public static final ByteString EMPTY
public static final ByteString[] EMPTY_ARRAY
public static byte[] asByteArray(ByteString byteString)
byteString - a ByteString or nullpublic static ByteString from(ByteArrayOutputStream stream)
ByteString whose value matches as if
ByteArrayOutputStream.toByteArray() was called for the given stream. Calling this
method avoids making an extra copy of the array. IMPORTANT! The given stream shall be as such,
that the byte[] returned by it's ByteArrayOutputStream.toByteArray() wont be modified
after returning. Returns null if given null stream.public static ByteString fromBitSet(BitSet set)
BitSet. This is the same as calling
ByteString.valueOf(set.toByteArray()). Returns null if given null. NOTE! that BitSet
only stores the info about the bits that are set, thus giving a BitSet from
toBitSet() to this method might not result in the same object, depending on the
position of set bits.public static ByteString fromBitSet(BitSet set, int minimumLengthInBytes)
fromBitSet(BitSet), but allows specifying a minimum length. If the result of
fromBitSet(BitSet) would produce a ByteString less than the given minimum, the
ByteString is padded with zero bytes until getLength() is equal to
the given minimum.public static ByteString fromHex(String hex)
hex - a String objectpublic static ByteString fromLong(long value)
ByteString where the given Long (OPC UA Int64) is OPC UA Binary encoded (i.e.
the same as-if IEncoder.putInt64(String, Long) would have been used) with the
ByteString.public static ByteString fromUUID(UUID guid)
ByteString where the given UUID is OPC UA Binary encoded (i.e. the same as-if
IEncoder.putGuid(String, UUID) would have been used) with the ByteString.public static boolean isNullOrEmpty(ByteString data)
EMPTY , false otherwise.public static ByteString valueOf(byte... byteArray)
byteArray - the byte arraypublic ByteString append(byte[] data)
public ByteString append(ByteString data)
public int compareTo(ByteString other)
compareTo in interface Comparable<ByteString>public void copyTo(ByteArrayOutputStream stream)
stream - the stream to copy to, not nullpublic void copyTo(ByteArrayOutputStream stream, int offset, int length)
copyTo(ByteArrayOutputStream), but allows specifying part of this ByteString
to be put to the stream.stream - the stream to copy to, not nulloffset - starting indexlength - number of bytes to copy from the offset index.IndexOutOfBoundsException - if invalid offsets or lengths are givenpublic void copyTo(IBinaryWriteable stream) throws IOException
IOExceptionpublic void copyTo(IBinaryWriteable stream, int offset, int length) throws IOException
copyTo(ByteArrayOutputStream, int, int), but for IBinaryWriteable, but
needs handling of IOException.IOExceptionpublic void copyTo(OutputStream stream) throws IOException
copyTo(ByteArrayOutputStream), but works for all OutputStream, but
needs handling of IOException.IOExceptionpublic void copyTo(OutputStream stream, int offset, int length) throws IOException
copyTo(ByteArrayOutputStream, int, int), but works for all
OutputStream, but needs handling of IOException.IOExceptionpublic int getLength()
public byte[] getValue()
public boolean isBitSet(int position)
BitFieldpublic BitSet toBitSet()
BitSet with the copy of the data of this ByteString. Modifying the
BitSet wont change this immutable ByteString. NOTE! that BitSet only
stores the info about the bits that are set, thus giving this BitSet back in
fromBitSet(BitSet) can cause a different getLength() to this object depending
on the positions of set bits.public String toHex()
CryptoUtil.toHex(byte[], int, boolean) with the value of this ByteString without
length prefix and 0 (no limit) for bytesPerRow.
Note that toString() calls CryptoUtil#toHex with length prefix.
String object.Copyright © 2026. All rights reserved.