FileDocCategorySizeDatePackage
JEIndexOutput.javaAPI DocApache Lucene 2.1.03836Wed Feb 14 10:46:08 GMT 2007org.apache.lucene.store.je

JEIndexOutput

public class JEIndexOutput extends IndexOutput
Port of Andi Vajda's DbDirectory to Java Edition of Berkeley Database
author
Aaron Donovan

Fields Summary
public static final int
BLOCK_SHIFT
The 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 voidclose()

        flush();
        file.modify(directory, length, System.currentTimeMillis());

        directory.openFiles.remove(this);
    
public voidflush()

        if (length > 0)
            block.put(directory);
    
public longgetFilePointer()

        return position;
    
public longlength()

        return length;
    
public voidseek(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 voidwriteByte(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 voidwriteBytes(byte[] b, int len)

        int blockPos = (int) (position & BLOCK_MASK);
        int offset = 0;

        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;