Class ImmutableBytes
java.lang.Object
com.inductiveautomation.ignition.common.ImmutableBytes
- All Implemented Interfaces:
Serializable
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ImmutableBytesShared instance of an instance for byte[0] -
Method Summary
Modifier and TypeMethodDescriptionstatic ImmutableBytescopyOf(byte[] bytes) Creates an ImmutableBytes instance by copying the given byte array.digest(Supplier<DigestBuilder> digestBuilderSupplier) Creates a newImmutableBytesinstance by taking a digest of this instance's bytes using a suppliedDigestBuilder.booleanstatic ImmutableBytesfromBase64String(Base64.Decoder decoder, String base64String) Decodes the given base64-encoded string into bytes using the givenBase64.Decoder.static ImmutableBytesCreates an ImmutableBytes instance by reading all available bytes from a filestatic ImmutableBytesfromHexString(String hexString) Decodes the given hex string into bytes.static ImmutableBytesfromHexString(HexFormat hexFormat, String hexString) Decodes the given hex string into bytes using the givenHexFormat.static ImmutableBytesfromRandomGenerator(RandomGenerator randomGenerator, int length) Generates a newImmutableBytesinstance by reading a configurable length of bytes from a givenRandomGenerator.static ImmutableBytesfromStream(InputStream stream) Creates an ImmutableBytes instance by reading all available bytes from an input stream.byteget(int index) byte[]get(int start, int end) Get a subsequence of the byte[] held by this objectgetAsBase64String(Base64.Encoder encoder) getAsHexString(HexFormat hexFormat) byte[]getBytes()getBytesAsString(Charset charset) longgetCrc32()booleanhasBytes()inthashCode()booleanisEmpty()intlength()static ImmutableBytesvoidupdateDigest(MessageDigest digest) CallsMessageDigest.update(byte[])with the bytes held by this objectvoidwriteToStream(OutputStream outputStream) Writes the bytes held by this object to the given output stream
-
Field Details
-
EMPTY
Shared instance of an instance for byte[0]
-
-
Method Details
-
copyOf
Creates an ImmutableBytes instance by copying the given byte array. -
fromFile
Creates an ImmutableBytes instance by reading all available bytes from a file- Throws:
IOException
-
fromStream
Creates an ImmutableBytes instance by reading all available bytes from an input stream. Note that this method does not close the stream.- Throws:
IOException
-
ofString
- Parameters:
string- The string to represent as bytes- Returns:
- An instance of ImmutableBytes representing the given string in UTF-8 encoding
-
fromHexString
Decodes the given hex string into bytes. Opposite ofgetAsHexString(). -
fromHexString
Decodes the given hex string into bytes using the givenHexFormat. Opposite ofgetAsHexString(HexFormat). -
fromBase64String
public static ImmutableBytes fromBase64String(@Nonnull Base64.Decoder decoder, @Nonnull String base64String) Decodes the given base64-encoded string into bytes using the givenBase64.Decoder. Opposite ofgetAsBase64String(Encoder). -
fromRandomGenerator
Generates a newImmutableBytesinstance by reading a configurable length of bytes from a givenRandomGenerator.- Parameters:
randomGenerator- theRandomGenerator. must not be null.length- the length of random bytes to generate. must not be negative.- Returns:
- a new
ImmutableBytesinstance backed by a byte array of the given length whose contents are provided by the givenRandomGenerator. never null. - Throws:
NullPointerException- if the randomGenerator argument is null
-
getBytes
public byte[] getBytes()- Returns:
- a copy of the byte array held by this object
-
getBytesAsString
- Returns:
- the bytes as a string, using UTF-8 encoding
-
getBytesAsString
- Parameters:
charset- The charset to use to interpret the bytes- Returns:
- the bytes as a string, using the given charset
-
getAsHexString
- Returns:
- the bytes as a hex string
- See Also:
-
getAsHexString
- Returns:
- the bytes as a hex string
- See Also:
-
getAsBase64String
- Parameters:
encoder- aBase64.Encoderused to base64-encode the bytes- Returns:
- the bytes as a base64-encoded string
- See Also:
-
getBytesAsStream
- Returns:
- the bytes as an input stream
-
getBytesAsReader
- Returns:
- the bytes as a reader, using UTF-8 encoding
-
writeToStream
Writes the bytes held by this object to the given output stream- Throws:
IOException
-
updateDigest
CallsMessageDigest.update(byte[])with the bytes held by this object -
digest
Creates a newImmutableBytesinstance by taking a digest of this instance's bytes using a suppliedDigestBuilder.- Parameters:
digestBuilderSupplier- aSupplierofDigestBuilder. must not be null.- Returns:
- a new
ImmutableBytesinstance backed by the digest of this instance's bytes - Throws:
NullPointerException- if the digestBuilderSupplier argument is null or the supplied DigestBuilder is null
-
getCrc32
public long getCrc32()- Returns:
- the CRC-32 checksum of the bytes
-
length
public int length()- Returns:
- the length of the byte array
-
hasBytes
public boolean hasBytes()- Returns:
- true if the byte array has a length greater than 0
-
isEmpty
public boolean isEmpty()- Returns:
- true if the byte array has a length of 0.
-
get
public byte get(int index) - Parameters:
index- the index within the byte array to fetch- Returns:
- the byte at the given index
-
get
public byte[] get(int start, int end) Get a subsequence of the byte[] held by this object- Parameters:
start- the start index (inclusive)end- the end index (exclusive)- Returns:
- a new byte[] containing the bytes from start to end
-
equals
-
hashCode
public int hashCode()
-