Example usage for org.apache.lucene.store BufferedIndexInput BufferedIndexInput

List of usage examples for org.apache.lucene.store BufferedIndexInput BufferedIndexInput

Introduction

In this page you can find the example usage for org.apache.lucene.store BufferedIndexInput BufferedIndexInput.

Prototype

public BufferedIndexInput(String resourceDesc) 

Source Link

Usage

From source file:com.nearinfinity.mele.store.db.MeleDirectory.java

License:Apache License

@Override
public IndexInput openInput(final String name) throws IOException {
    if (!fileExists(name)) {
        touchFile(name);//from  w  w  w . ja  va  2s  . c om
    }
    final long fileLength = fileLength(name);
    return new BufferedIndexInput(blockSize / 2) {
        @Override
        public long length() {
            return fileLength;
        }

        @Override
        public void close() throws IOException {

        }

        @Override
        protected void seekInternal(long pos) throws IOException {
        }

        @Override
        protected void readInternal(byte[] b, int off, int len) throws IOException {
            long position = getFilePointer();
            while (len > 0) {
                long blockId = getBlock(position, blockShift);
                int innerPosition = (int) getPosition(position, blockMask);
                byte[] block = store.fetchBlock(name, blockId);
                int length = Math.min(len, block.length - innerPosition);
                System.arraycopy(block, innerPosition, b, off, length);
                position += length;
                len -= length;
                off += length;
            }
        }
    };
}