Methods Summary |
---|
public void | close()
// nothing to do here
|
public long | getFilePointer()
return currentBufferIndex < 0 ? 0 : bufferStart + bufferPosition;
|
public long | length()
return length;
|
public byte | readByte()
if (bufferPosition >= bufferLength) {
currentBufferIndex++;
switchCurrentBuffer();
}
return currentBuffer[bufferPosition++];
|
public void | readBytes(byte[] b, int offset, int len)
while (len > 0) {
if (bufferPosition >= bufferLength) {
currentBufferIndex++;
switchCurrentBuffer();
}
int remainInBuffer = bufferLength - bufferPosition;
int bytesToCopy = len < remainInBuffer ? len : remainInBuffer;
System.arraycopy(currentBuffer, bufferPosition, b, offset, bytesToCopy);
offset += bytesToCopy;
len -= bytesToCopy;
bufferPosition += bytesToCopy;
}
|
public void | seek(long pos)
long bufferStart = currentBufferIndex * BUFFER_SIZE;
if (pos < bufferStart || pos >= bufferStart + BUFFER_SIZE) {
currentBufferIndex = (int) (pos / BUFFER_SIZE);
switchCurrentBuffer();
}
bufferPosition = (int) (pos % BUFFER_SIZE);
|
private final void | switchCurrentBuffer()
if (currentBufferIndex >= file.buffers.size()) {
// end of file reached, no more buffers left
throw new IOException("Read past EOF");
} else {
currentBuffer = (byte[]) file.buffers.get(currentBufferIndex);
bufferPosition = 0;
bufferStart = BUFFER_SIZE * currentBufferIndex;
bufferLength = (int) (length - bufferStart);
if (bufferLength > BUFFER_SIZE) {
bufferLength = BUFFER_SIZE;
}
}
|