Skip to content

Commit

Permalink
Remove whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Oct 9, 2024
1 parent 61079e1 commit bd836cf
Showing 1 changed file with 0 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,16 @@ public int read() throws IOException {
block = getFirstBlock();
readFirst = true;
}

if (block != null && blockIndex >= block.bytes.length) {
block = block.getNext();
blockIndex = 0;
}

if (null == block) {
return -1;
}

if (blockIndex >= block.bytes.length) {
return -1;
}

return 0xff & block.bytes[blockIndex++];
}

Expand All @@ -95,30 +91,24 @@ public int read(final byte[] array, final int off, final int len) throws IOExcep
if (len == 0) {
return 0;
}

// optimized block read

if (null == block) {
if (readFirst) {
return -1;
}
block = getFirstBlock();
readFirst = true;
}

if (block != null && blockIndex >= block.bytes.length) {
block = block.getNext();
blockIndex = 0;
}

if (null == block) {
return -1;
}

if (blockIndex >= block.bytes.length) {
return -1;
}

final int readSize = Math.min(len, block.bytes.length - blockIndex);
System.arraycopy(block.bytes, blockIndex, array, off, readSize);
blockIndex += readSize;
Expand All @@ -127,13 +117,10 @@ public int read(final byte[] array, final int off, final int len) throws IOExcep

@Override
public long skip(final long n) throws IOException {

long remaining = n;

if (n <= 0) {
return 0;
}

while (remaining > 0) {
// read the first block
if (null == block) {
Expand All @@ -143,27 +130,21 @@ public long skip(final long n) throws IOException {
block = getFirstBlock();
readFirst = true;
}

// get next block
if (block != null && blockIndex >= block.bytes.length) {
block = block.getNext();
blockIndex = 0;
}

if (null == block) {
break;
}

if (blockIndex >= block.bytes.length) {
break;
}

final int readSize = Math.min((int) Math.min(BLOCK_SIZE, remaining), block.bytes.length - blockIndex);

blockIndex += readSize;
remaining -= readSize;
}

return n - remaining;
}

Expand All @@ -188,10 +169,8 @@ public byte[] getByteArray(final long position, final int length) throws IOExcep
throw new ImagingException(
"Could not read block (block start: " + position + ", block length: " + length + ", data length: " + streamLength + ").");
}

final InputStream cis = getInputStream();
BinaryFunctions.skipBytes(cis, position);

final byte[] bytes = Allocator.byteArray(length);
int total = 0;
while (true) {
Expand Down

0 comments on commit bd836cf

Please sign in to comment.