Example usage for org.apache.lucene.codecs CodecUtil checkFooter

List of usage examples for org.apache.lucene.codecs CodecUtil checkFooter

Introduction

In this page you can find the example usage for org.apache.lucene.codecs CodecUtil checkFooter.

Prototype

public static void checkFooter(ChecksumIndexInput in, Throwable priorException) throws IOException 

Source Link

Document

Validates the codec footer previously written by #writeFooter , optionally passing an unexpected exception that has already occurred.

Usage

From source file:com.vmware.xenon.services.common.Lucene60FieldInfosFormatWithCache.java

License:Open Source License

@Override
public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext context)
        throws IOException {
    //////////////////////
    boolean checkInfosCache = true;
    //////////////////////
    final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, EXTENSION);
    try (ChecksumIndexInput input = directory.openChecksumInput(fileName, context)) {
        Throwable priorE = null;//  w  w  w  .j  a  v  a2  s.c o  m
        FieldInfo[] infos = null;
        try {
            CodecUtil.checkIndexHeader(input, Lucene60FieldInfosFormatWithCache.CODEC_NAME,
                    Lucene60FieldInfosFormatWithCache.FORMAT_START,
                    Lucene60FieldInfosFormatWithCache.FORMAT_CURRENT, segmentInfo.getId(), segmentSuffix);

            final int size = input.readVInt(); //read in the size
            infos = new FieldInfo[size];

            // previous field's attribute map, we share when possible:
            Map<String, String> lastAttributes = Collections.emptyMap();

            for (int i = 0; i < size; i++) {
                String name = input.readString();
                final int fieldNumber = input.readVInt();
                if (fieldNumber < 0) {
                    throw new CorruptIndexException(
                            "invalid field number for field: " + name + ", fieldNumber=" + fieldNumber, input);
                }
                byte bits = input.readByte();
                boolean storeTermVector = (bits & STORE_TERMVECTOR) != 0;
                boolean omitNorms = (bits & OMIT_NORMS) != 0;
                boolean storePayloads = (bits & STORE_PAYLOADS) != 0;

                final IndexOptions indexOptions = getIndexOptions(input, input.readByte());

                // DV Types are packed in one byte
                final DocValuesType docValuesType = getDocValuesType(input, input.readByte());
                final long dvGen = input.readLong();
                Map<String, String> attributes = input.readMapOfStrings();
                // just use the last field's map if its the same
                if (attributes.equals(lastAttributes)) {
                    attributes = lastAttributes;
                }
                lastAttributes = attributes;
                int pointDimensionCount = input.readVInt();
                int pointNumBytes;
                if (pointDimensionCount != 0) {
                    pointNumBytes = input.readVInt();
                } else {
                    pointNumBytes = 0;
                }

                try {
                    //////////////////////
                    if (dvGen >= 0) {
                        // skip fields with docValues, they don't cache well
                        checkInfosCache = false;
                        infos[i] = new FieldInfo(name, fieldNumber, storeTermVector, omitNorms, storePayloads,
                                indexOptions, docValuesType, dvGen, attributes, pointDimensionCount,
                                pointNumBytes);
                    } else {
                        infos[i] = this.cache.dedupFieldInfo(name, fieldNumber, storeTermVector, omitNorms,
                                storePayloads, indexOptions, docValuesType, dvGen, attributes,
                                pointDimensionCount, pointNumBytes);
                    }
                    //////////////////////
                } catch (IllegalStateException e) {
                    throw new CorruptIndexException(
                            "invalid fieldinfo for field: " + name + ", fieldNumber=" + fieldNumber, input, e);
                }
            }
        } catch (Throwable exception) {
            priorE = exception;
        } finally {
            CodecUtil.checkFooter(input, priorE);
        }

        //////////////////////
        if (checkInfosCache) {
            return this.cache.dedupFieldInfos(infos);
        } else {
            FieldInfos result = new FieldInfos(infos);
            this.cache.trimFieldInfos(result);
            return result;
        }
        //////////////////////
    }
}