Skip to content

Commit

Permalink
Read bytes more efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Oct 29, 2023
1 parent 300d2a7 commit 4fe0b4b
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,21 @@ private static void populateByteArray(byte[] array, LittleEndien stream, int cou
int stride = Math.max(dataLength, byteStride);
int end = count * stride + byteOffset;
stream.skipBytes(byteOffset);

if (dataLength == stride) {
byte[] buffer = new byte[end - index];
stream.read(buffer, 0, buffer.length);
System.arraycopy(buffer, 0, array, 0, buffer.length);

return;
}

int arrayIndex = 0;
byte[] buffer = new byte[numComponents];
while (index < end) {
for (int i = 0; i < numComponents; i++) {
array[arrayIndex] = stream.readByte();
arrayIndex++;
}
stream.read(buffer, 0, numComponents);
System.arraycopy(buffer, 0, array, arrayIndex, numComponents);
arrayIndex += numComponents;
if (dataLength < stride) {
stream.skipBytes(stride - dataLength);
}
Expand Down

0 comments on commit 4fe0b4b

Please sign in to comment.