Example usage for org.apache.lucene.util.packed PackedInts getReaderNoHeader

List of usage examples for org.apache.lucene.util.packed PackedInts getReaderNoHeader

Introduction

In this page you can find the example usage for org.apache.lucene.util.packed PackedInts getReaderNoHeader.

Prototype

public static Reader getReaderNoHeader(DataInput in, Format format, int version, int valueCount,
        int bitsPerValue) throws IOException 

Source Link

Document

Expert: Restore a Reader from a stream without reading metadata at the beginning of the stream.

Usage

From source file:com.lucure.core.codec.CompressingStoredFieldsIndexReader.java

License:Apache License

CompressingStoredFieldsIndexReader(IndexInput fieldsIndexIn, SegmentInfo si) throws IOException {
    maxDoc = si.getDocCount();/* w w  w  . jav  a 2s .c o  m*/
    int[] docBases = new int[16];
    long[] startPointers = new long[16];
    int[] avgChunkDocs = new int[16];
    long[] avgChunkSizes = new long[16];
    PackedInts.Reader[] docBasesDeltas = new PackedInts.Reader[16];
    PackedInts.Reader[] startPointersDeltas = new PackedInts.Reader[16];

    final int packedIntsVersion = fieldsIndexIn.readVInt();

    int blockCount = 0;

    for (;;) {
        final int numChunks = fieldsIndexIn.readVInt();
        if (numChunks == 0) {
            break;
        }
        if (blockCount == docBases.length) {
            final int newSize = ArrayUtil.oversize(blockCount + 1, 8);
            docBases = Arrays.copyOf(docBases, newSize);
            startPointers = Arrays.copyOf(startPointers, newSize);
            avgChunkDocs = Arrays.copyOf(avgChunkDocs, newSize);
            avgChunkSizes = Arrays.copyOf(avgChunkSizes, newSize);
            docBasesDeltas = Arrays.copyOf(docBasesDeltas, newSize);
            startPointersDeltas = Arrays.copyOf(startPointersDeltas, newSize);
        }

        // doc bases
        docBases[blockCount] = fieldsIndexIn.readVInt();
        avgChunkDocs[blockCount] = fieldsIndexIn.readVInt();
        final int bitsPerDocBase = fieldsIndexIn.readVInt();
        if (bitsPerDocBase > 32) {
            throw new CorruptIndexException("Corrupted bitsPerDocBase (resource=" + fieldsIndexIn + ")");
        }
        docBasesDeltas[blockCount] = PackedInts.getReaderNoHeader(fieldsIndexIn, PackedInts.Format.PACKED,
                packedIntsVersion, numChunks, bitsPerDocBase);

        // start pointers
        startPointers[blockCount] = fieldsIndexIn.readVLong();
        avgChunkSizes[blockCount] = fieldsIndexIn.readVLong();
        final int bitsPerStartPointer = fieldsIndexIn.readVInt();
        if (bitsPerStartPointer > 64) {
            throw new CorruptIndexException("Corrupted bitsPerStartPointer (resource=" + fieldsIndexIn + ")");
        }
        startPointersDeltas[blockCount] = PackedInts.getReaderNoHeader(fieldsIndexIn, PackedInts.Format.PACKED,
                packedIntsVersion, numChunks, bitsPerStartPointer);

        ++blockCount;
    }

    this.docBases = Arrays.copyOf(docBases, blockCount);
    this.startPointers = Arrays.copyOf(startPointers, blockCount);
    this.avgChunkDocs = Arrays.copyOf(avgChunkDocs, blockCount);
    this.avgChunkSizes = Arrays.copyOf(avgChunkSizes, blockCount);
    this.docBasesDeltas = Arrays.copyOf(docBasesDeltas, blockCount);
    this.startPointersDeltas = Arrays.copyOf(startPointersDeltas, blockCount);
}