forked from qoire/ledger4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteUtilities.java
More file actions
36 lines (29 loc) · 1008 Bytes
/
ByteUtilities.java
File metadata and controls
36 lines (29 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.aion.ledger;
import javax.annotation.Nonnull;
public class ByteUtilities {
@Nonnull
public static byte[] merge(@Nonnull final byte[] in1, @Nonnull final byte[] in2) {
byte[] out = new byte[in1.length + in2.length];
System.arraycopy(in1, 0, out, 0, in1.length);
System.arraycopy(in2, 0, out, in1.length, in2.length);
return out;
}
@Nonnull
public static byte[] trimHead(@Nonnull final byte[] in, final int amount) {
if (amount >= in.length) {
return new byte[0];
}
byte[] out = new byte[in.length - amount];
System.arraycopy(in, amount, out, 0, in.length - amount);
return out;
}
@Nonnull
public static byte[] trimTail(@Nonnull final byte[] in, final int amount) {
if (amount >= in.length) {
return new byte[0];
}
byte[] out = new byte[in.length - amount];
System.arraycopy(in, 0, out, 0, out.length);
return out;
}
}