ByteArray class

A wrapper for byte arrays similar to Java's byte[] with utility methods.

This class provides a convenient interface for working with byte arrays, wrapping Dart's List<int> with Java-like methods and additional utilities.

Example usage:

ByteArray bytes = ByteArray.fromString("Hello");
ByteArray copy = bytes.copy();
bytes.set(0, 72); // Change 'H' to 'H' (same value)

print(bytes.toString()); // "Hello"
print(bytes.length); // 5

Constructors

ByteArray(int size)
Creates a ByteArray with the specified size, filled with zeros.
factory
ByteArray.filled(int size, int fillValue)
Creates a ByteArray filled with the specified value.
factory
ByteArray.fromList(List<int> bytes)
Creates a ByteArray from an existing list of bytes.
factory
ByteArray.fromString(String str)
Creates a ByteArray from a string.
factory
ByteArray.fromUint8List(Uint8List data)
Creates a ByteArray from a Uint8List.
factory

Properties

hashCode → int
Returns the hash code for this byte array.
no setteroverride
isEmpty → bool
Returns true if this array is empty.
no setter
isNotEmpty → bool
Returns true if this array is not empty.
no setter
length → int
Returns the length of this byte array.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

concat(ByteArray other) → ByteArray
Concatenates this byte array with another.
contains(int value) → bool
Returns true if this array contains the specified byte.
copy([int? start, int? end]) → ByteArray
Creates a copy of this byte array.
copyTo(int srcPos, ByteArray dest, int destPos, int length) → void
Copies a portion of this array to another array.
fill(int value, [int? start, int? end]) → void
Fills this array with the specified value.
get(int index) → int
Gets the byte at the specified index.
indexOf(int value, [int start = 0]) → int
Returns the index of the first occurrence of the specified byte.
lastIndexOf(int value, [int? start]) → int
Returns the index of the last occurrence of the specified byte.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reverse() → void
Reverses the order of bytes in this array.
set(int index, int value) → void
Sets the byte at the specified index.
sort() → void
Sorts the bytes in this array.
subArray(int start, [int? end]) → ByteArray
Returns a subarray of this byte array.
toHexString([String separator = '']) → String
Returns a hexadecimal string representation of this byte array.
toList() → List<int>
Converts this byte array to a List<int>.
toString() → String
Returns a string representation of this byte array.
override
toStringAsChars() → String
Converts this byte array to a string.
toUint8List() → Uint8List
Converts this byte array to a Uint8List.

Operators

operator +(ByteArray other) → ByteArray
Concatenation operator
operator ==(Object other) → bool
Returns true if this byte array equals the specified object.
override
operator [](int index) → int
Operator overloads
operator []=(int index, int value) → void

Static Methods

compare(ByteArray a, ByteArray b) → int
Static utility methods Compares two byte arrays lexicographically.
equals(ByteArray a, ByteArray b) → bool
Returns true if two byte arrays are equal.
fromHexString(String hexString) → ByteArray
Creates a ByteArray from a hexadecimal string.