JEIndexOutputpublic class JEIndexOutput extends IndexOutput Port of Andi Vajda's DbDirectory to Java Edition of Berkeley Database |
Fields Summary |
---|
public static final int | BLOCK_SHIFTThe size of data blocks, currently 16k (2^14), is determined by this
constant. | public static final int | BLOCK_LEN | public static final int | BLOCK_MASK | protected long | position | protected long | length | protected JEDirectory | directory | protected Block | block | protected File | file |
Constructors Summary |
---|
protected JEIndexOutput(JEDirectory directory, String name, boolean create)
super();
this.directory = directory;
file = new File(directory, name, create);
block = new Block(file);
length = file.getLength();
seek(length);
block.get(directory);
directory.openFiles.add(this);
|
Methods Summary |
---|
public void | close()
flush();
file.modify(directory, length, System.currentTimeMillis());
directory.openFiles.remove(this);
| public void | flush()
if (length > 0)
block.put(directory);
| public long | getFilePointer()
return position;
| public long | length()
return length;
| public void | seek(long pos)
if (pos > length)
throw new IOException("seeking past end of file");
if ((pos >>> BLOCK_SHIFT) == (position >>> BLOCK_SHIFT))
position = pos;
else {
block.put(directory);
block.seek(pos);
block.get(directory);
position = pos;
}
| public void | writeByte(byte b)
int blockPos = (int) (position++ & BLOCK_MASK);
block.getData()[blockPos] = b;
if (blockPos + 1 == BLOCK_LEN) {
block.put(directory);
block.seek(position);
block.get(directory);
}
if (position > length)
length = position;
| public void | writeBytes(byte[] b, int offset, int len)
int blockPos = (int) (position & BLOCK_MASK);
while (blockPos + len >= BLOCK_LEN) {
int blockLen = BLOCK_LEN - blockPos;
System.arraycopy(b, offset, block.getData(), blockPos, blockLen);
block.put(directory);
len -= blockLen;
offset += blockLen;
position += blockLen;
block.seek(position);
block.get(directory);
blockPos = 0;
}
if (len > 0) {
System.arraycopy(b, offset, block.getData(), blockPos, len);
position += len;
}
if (position > length)
length = position;
|
|