git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@489 f203690c-595d-4dc9-a70b-905162fa7fd2tags/jackcess-1.2.2
@@ -531,6 +531,26 @@ public final class ByteUtil { | |||
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. | |||
@@ -608,8 +628,7 @@ public final class ByteUtil { | |||
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 |
@@ -1277,8 +1277,7 @@ public class Column implements Comparable<Column> { | |||
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 { |
@@ -955,9 +955,7 @@ public class IndexPageCache | |||
} | |||
// need new prefix | |||
byte[] tmpPrefix = new byte[len]; | |||
System.arraycopy(prefix, 0, tmpPrefix, 0, len); | |||
prefix = tmpPrefix; | |||
prefix = ByteUtil.copyOf(prefix, len); | |||
} | |||
return prefix; |
@@ -487,9 +487,7 @@ public abstract class JetFormat { | |||
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; } |