ByteTuple
This commit is contained in:
@@ -23,6 +23,8 @@ import org.redkale.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
public final class ByteArray implements ByteTuple {
|
public final class ByteArray implements ByteTuple {
|
||||||
|
|
||||||
|
static final byte[] EMPTY_BYTES = new byte[0];
|
||||||
|
|
||||||
private byte[] content;
|
private byte[] content;
|
||||||
|
|
||||||
private int count;
|
private int count;
|
||||||
@@ -431,7 +433,7 @@ public final class ByteArray implements ByteTuple {
|
|||||||
*/
|
*/
|
||||||
public byte[] getBytes(int offset, int length) {
|
public byte[] getBytes(int offset, int length) {
|
||||||
if (length < 1) {
|
if (length < 1) {
|
||||||
return new byte[0];
|
return EMPTY_BYTES;
|
||||||
}
|
}
|
||||||
byte[] bs = new byte[length];
|
byte[] bs = new byte[length];
|
||||||
System.arraycopy(this.content, offset, bs, 0, length);
|
System.arraycopy(this.content, offset, bs, 0, length);
|
||||||
|
|||||||
@@ -27,4 +27,22 @@ public interface ByteTuple {
|
|||||||
int o = offset();
|
int o = offset();
|
||||||
return Arrays.copyOfRange(content(), o, o + length());
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user