ByteTuple

This commit is contained in:
redkale
2024-08-19 19:47:38 +08:00
parent b48182f7cc
commit 254ab9a25a
2 changed files with 21 additions and 1 deletions

View File

@@ -23,6 +23,8 @@ import org.redkale.annotation.Nullable;
*/
public final class ByteArray implements ByteTuple {
static final byte[] EMPTY_BYTES = new byte[0];
private byte[] content;
private int count;
@@ -431,7 +433,7 @@ public final class ByteArray implements ByteTuple {
*/
public byte[] getBytes(int offset, int length) {
if (length < 1) {
return new byte[0];
return EMPTY_BYTES;
}
byte[] bs = new byte[length];
System.arraycopy(this.content, offset, bs, 0, length);

View File

@@ -27,4 +27,22 @@ public interface ByteTuple {
int o = offset();
return Arrays.copyOfRange(content(), o, o + length());
}
public static final ByteTuple EMPTY = new ByteTuple() {
@Override
public byte[] content() {
return ByteArray.EMPTY_BYTES;
}
@Override
public int offset() {
return 0;
}
@Override
public int length() {
return 0;
}
};
}