ByteArray.filled constructor
Creates a ByteArray filled with the specified value.
size
the size of the array
fillValue
the value to fill with (0-255)
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
Implementation
factory ByteArray.filled(int size, int fillValue) {
if (fillValue < 0 || fillValue > 255) {
throw InvalidArgumentException('Fill value must be between 0 and 255, got: $fillValue');
}
return ByteArray._(List<int>.filled(size, fillValue));
}