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

JEIndexInput

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

Fields Summary
protected long
position
protected long
length
protected JEDirectory
directory
protected Block
block
protected File
file
Constructors Summary
protected JEIndexInput(JEDirectory 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 {
            JEIndexInput clone = (JEIndexInput) 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(file.getName() + ": Reading past end of file");

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

        if (blockPos + 1 == JEIndexOutput.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 & JEIndexOutput.BLOCK_MASK);

            while (blockPos + len >= JEIndexOutput.BLOCK_LEN) {
                int blockLen = JEIndexOutput.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 >>> JEIndexOutput.BLOCK_SHIFT) != (position >>> JEIndexOutput.BLOCK_SHIFT)) {
            block.seek(pos);
            block.get(directory);
        }

        position = pos;