Skip to content

Commit 28bc15b

Browse files
authored
Merge pull request #34 from petrukhnov/master
Allocate methods that return MutableBytes
2 parents 7238f6c + 586c1a8 commit 28bc15b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/java/at/favre/lib/bytes/MutableBytes.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ public final class MutableBytes extends Bytes implements AutoCloseable {
3838
super(byteArray, byteOrder, new Factory());
3939
}
4040

41+
/**
42+
* Creates a new instance with an empty array filled with zeros.
43+
*
44+
* @param length of the internal array
45+
* @return new instance
46+
*/
47+
public static MutableBytes allocate(int length) {
48+
return allocate(length, (byte) 0);
49+
}
50+
51+
/**
52+
* Creates a new instance with an empty array filled with given defaultValue
53+
*
54+
* @param length of the internal array
55+
* @param defaultValue to fill with
56+
* @return new instance
57+
*/
58+
public static MutableBytes allocate(int length, byte defaultValue) {
59+
return Bytes.allocate(length, defaultValue).mutable();
60+
}
61+
4162
@Override
4263
public boolean isMutable() {
4364
return true;

0 commit comments

Comments
 (0)