FileDocCategorySizeDatePackage
DbIndexInput.javaAPI DocApache Lucene 2.1.03850Wed Feb 14 10:46:08 GMT 2007org.apache.lucene.store.db

DbIndexInput

public class DbIndexInput extends IndexInput
author
Andi Vajda

Fields Summary
protected long
position
protected long
length
protected DbDirectory
directory
protected Block
block
protected File
file
Constructors Summary
protected DbIndexInput(DbDirectory directory, String name)


        
         
    
        super();

        this.directory = directory;

        this.file = new File(name);
        if (!file.exists(directory))
            throw new IOException("File does not exist: " + name);

        length = file.getLength();

        block = new Block(file);
        block.get(directory);
    
Methods Summary
public java.lang.Objectclone()

        try {
            DbIndexInput clone = (DbIndexInput) super.clone();

            clone.block = new Block(file);
            clone.block.seek(position);
            clone.block.get(directory);

            return clone;
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage());
        }
    
public voidclose()

    
public longgetFilePointer()

        return position;
    
public longlength()

        return length;
    
public bytereadByte()

        if (position + 1 > length)
            throw new IOException("Reading past end of file");

        int blockPos = (int) (position++ & DbIndexOutput.BLOCK_MASK);
        byte b = block.getData()[blockPos];

        if (blockPos + 1 == DbIndexOutput.BLOCK_LEN)
        {
            block.seek(position);
            block.get(directory);
        }

        return b;
    
public voidreadBytes(byte[] b, int offset, int len)

        if (position + len > length)
            throw new IOException("Reading past end of file");
        else
        {
            int blockPos = (int) (position & DbIndexOutput.BLOCK_MASK);

            while (blockPos + len >= DbIndexOutput.BLOCK_LEN) {
                int blockLen = DbIndexOutput.BLOCK_LEN - blockPos;

                System.arraycopy(block.getData(), blockPos,
                                 b, offset, blockLen);

                len -= blockLen;
                offset += blockLen;
                position += blockLen;

                block.seek(position);
                block.get(directory);
                blockPos = 0;
            }

            if (len > 0)
            {
                System.arraycopy(block.getData(), blockPos, b, offset, len);
                position += len;
            }
        }
    
public voidseek(long pos)

        if (pos > length)
            throw new IOException("seeking past end of file");

        if ((pos >>> DbIndexOutput.BLOCK_SHIFT) !=
            (position >>> DbIndexOutput.BLOCK_SHIFT))
        {
            block.seek(pos);
            block.get(directory);
        }

        position = pos;