Example usage for org.apache.lucene.index SegmentInfo setFiles

List of usage examples for org.apache.lucene.index SegmentInfo setFiles

Introduction

In this page you can find the example usage for org.apache.lucene.index SegmentInfo setFiles.

Prototype

Set setFiles

To view the source code for org.apache.lucene.index SegmentInfo setFiles.

Click Source Link

Usage

From source file:org.apache.blur.lucene.codec.Blur022SegmentInfoReader.java

License:Apache License

@Override
public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {
    final String fileName = IndexFileNames.segmentFileName(segment, "", Blur022SegmentInfoFormat.SI_EXTENSION);
    final IndexInput input = dir.openInput(fileName, context);
    boolean success = false;
    try {//from  w w w  .j  ava2  s .  c o  m
        CodecUtil.checkHeader(input, Blur022SegmentInfoFormat.CODEC_NAME,
                Blur022SegmentInfoFormat.VERSION_START, Blur022SegmentInfoFormat.VERSION_CURRENT);
        final String version = input.readString();
        final int docCount = input.readInt();
        if (docCount < 0) {
            throw new CorruptIndexException("invalid docCount: " + docCount + " (resource=" + input + ")");
        }
        final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
        final Map<String, String> diagnostics = input.readStringStringMap();
        final Map<String, String> attributes = input.readStringStringMap();
        final Set<String> files = input.readStringSet();

        if (input.getFilePointer() != input.length()) {
            throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read "
                    + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
        }

        final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null,
                diagnostics, Collections.unmodifiableMap(attributes));
        si.setFiles(files);

        success = true;

        return si;

    } finally {
        if (!success) {
            IOUtils.closeWhileHandlingException(input);
        } else {
            input.close();
        }
    }
}