Methods Summary |
---|
public void | close()
flush();
|
public void | flush()
file.setLastModified(System.currentTimeMillis());
setFileLength();
|
public long | getFilePointer()
return currentBufferIndex < 0 ? 0 : bufferStart + bufferPosition;
|
public long | length()
return file.length;
|
public void | reset()Resets this to an empty buffer.
try {
seek(0);
} catch (IOException e) { // should never happen
throw new RuntimeException(e.toString());
}
file.setLength(0);
|
public void | seek(long pos)
// set the file length in case we seek back
// and flush() has not been called yet
setFileLength();
if (pos < bufferStart || pos >= bufferStart + bufferLength) {
currentBufferIndex = (int) (pos / BUFFER_SIZE);
switchCurrentBuffer();
}
bufferPosition = (int) (pos % BUFFER_SIZE);
|
private void | setFileLength()
long pointer = bufferStart + bufferPosition;
if (pointer > file.length) {
file.setLength(pointer);
}
|
private final void | switchCurrentBuffer()
if (currentBufferIndex == file.buffers.size()) {
currentBuffer = file.addBuffer(BUFFER_SIZE);
} else {
currentBuffer = (byte[]) file.buffers.get(currentBufferIndex);
}
bufferPosition = 0;
bufferStart = BUFFER_SIZE * currentBufferIndex;
bufferLength = currentBuffer.length;
|
public void | writeByte(byte b)
if (bufferPosition == bufferLength) {
currentBufferIndex++;
switchCurrentBuffer();
}
currentBuffer[bufferPosition++] = b;
|
public void | writeBytes(byte[] b, int offset, int len)
while (len > 0) {
if (bufferPosition == bufferLength) {
currentBufferIndex++;
switchCurrentBuffer();
}
int remainInBuffer = currentBuffer.length - bufferPosition;
int bytesToCopy = len < remainInBuffer ? len : remainInBuffer;
System.arraycopy(b, offset, currentBuffer, bufferPosition, bytesToCopy);
offset += bytesToCopy;
len -= bytesToCopy;
bufferPosition += bytesToCopy;
}
|
public void | writeTo(org.apache.lucene.store.IndexOutput out)Copy the current contents of this buffer to the named output.
flush();
final long end = file.length;
long pos = 0;
int buffer = 0;
while (pos < end) {
int length = BUFFER_SIZE;
long nextPos = pos + length;
if (nextPos > end) { // at the last buffer
length = (int)(end - pos);
}
out.writeBytes((byte[])file.buffers.get(buffer++), length);
pos = nextPos;
}
|