return newPos;
}
+ /**
+ * Returns a copy of the the given array of the given length.
+ */
+ public static byte[] copyOf(byte[] arr, int newLength)
+ {
+ return copyOf(arr, 0, newLength);
+ }
+
+ /**
+ * Returns a copy of the the given array of the given length starting at the
+ * given position.
+ */
+ public static byte[] copyOf(byte[] arr, int offset, int newLength)
+ {
+ byte[] newArr = new byte[newLength];
+ int srcLen = arr.length - offset;
+ System.arraycopy(arr, offset, newArr, 0, Math.min(srcLen, newLength));
+ return newArr;
+ }
+
/**
* Utility byte stream similar to ByteArrayOutputStream but with extended
* accessibility to the bytes.
result = _bytes;
_bytes = null;
} else {
- result = new byte[_length];
- System.arraycopy(_bytes, 0, result, 0, _length);
+ result = copyOf(_bytes, _length);
if(_lastLength == _length) {
// if we get the same result length bytes twice in a row, clear the
// _bytes so that the next _bytes will be _lastLength
int dataLength = dataEnd - dataStart;
if(inCompressedMode) {
// handle compressed data
- byte[] tmpData = new byte[dataLength];
- System.arraycopy(data, dataStart, tmpData, 0, dataLength);
+ byte[] tmpData = ByteUtil.copyOf(data, dataStart, dataLength);
expander.reset();
textBuf.append(expander.expand(tmpData));
} else {
protected int defineOffsetMaskedHeader() { return 24; }
@Override
protected byte[] defineHeaderMask() {
- byte[] mask = new byte[BASE_HEADER_MASK.length - 2];
- System.arraycopy(BASE_HEADER_MASK, 0, mask, 0, mask.length);
- return mask;
+ return ByteUtil.copyOf(BASE_HEADER_MASK, BASE_HEADER_MASK.length - 2);
}
@Override
protected int defineOffsetHeaderDate() { return -1; }