FileDocCategorySizeDatePackage
DbIndexOutput.javaAPI DocApache Lucene 1.93668Mon Feb 20 09:18:00 GMT 2006org.apache.lucene.store.db

DbIndexOutput

public class DbIndexOutput extends IndexOutput
author
Andi Vajda

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 DbDirectory
directory
protected Block
block
protected File
file
Constructors Summary
protected DbIndexOutput(DbDirectory 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;