Example usage for org.apache.lucene.store DataInput readString

List of usage examples for org.apache.lucene.store DataInput readString

Introduction

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

Prototype

public String readString() throws IOException 

Source Link

Document

Reads a string.

Usage

From source file:com.browseengine.bobo.geosearch.impl.MappedFieldNameFilterConverter.java

License:Apache License

@Override
public void loadFromInput(DataInput input) throws IOException {
    int version = input.readVInt(); //read version

    int mapSize = input.readVInt();
    bitmasks = new HashMap<String, Byte>(mapSize);
    for (int i = 0; i < mapSize; i++) {
        String fieldName = input.readString();
        Byte filterByte = input.readByte();

        bitmasks.put(fieldName, filterByte);
    }/*  w ww. j ava2 s  . c  om*/
}

From source file:com.github.cstoku.neologd.unidic.lucene.analysis.ja.dict.BinaryDictionary.java

License:Apache License

protected BinaryDictionary() throws IOException {
    InputStream mapIS = null, dictIS = null, posIS = null;
    int[] targetMapOffsets = null, targetMap = null;
    String[] posDict = null;/*from   www  . j ava  2s . co m*/
    String[] inflFormDict = null;
    String[] inflTypeDict = null;
    ByteBuffer buffer = null;
    boolean success = false;
    try {
        mapIS = getResource(TARGETMAP_FILENAME_SUFFIX);
        mapIS = new BufferedInputStream(mapIS);
        DataInput in = new InputStreamDataInput(mapIS);
        CodecUtil.checkHeader(in, TARGETMAP_HEADER, VERSION, VERSION);
        targetMap = new int[in.readVInt()];
        targetMapOffsets = new int[in.readVInt()];
        int accum = 0, sourceId = 0;
        for (int ofs = 0; ofs < targetMap.length; ofs++) {
            final int val = in.readVInt();
            if ((val & 0x01) != 0) {
                targetMapOffsets[sourceId] = ofs;
                sourceId++;
            }
            accum += val >>> 1;
            targetMap[ofs] = accum;
        }
        if (sourceId + 1 != targetMapOffsets.length)
            throw new IOException("targetMap file format broken");
        targetMapOffsets[sourceId] = targetMap.length;
        mapIS.close();
        mapIS = null;

        posIS = getResource(POSDICT_FILENAME_SUFFIX);
        posIS = new BufferedInputStream(posIS);
        in = new InputStreamDataInput(posIS);
        CodecUtil.checkHeader(in, POSDICT_HEADER, VERSION, VERSION);
        int posSize = in.readVInt();
        posDict = new String[posSize];
        inflTypeDict = new String[posSize];
        inflFormDict = new String[posSize];
        for (int j = 0; j < posSize; j++) {
            posDict[j] = in.readString();
            inflTypeDict[j] = in.readString();
            inflFormDict[j] = in.readString();
            // this is how we encode null inflections
            if (inflTypeDict[j].length() == 0) {
                inflTypeDict[j] = null;
            }
            if (inflFormDict[j].length() == 0) {
                inflFormDict[j] = null;
            }
        }
        posIS.close();
        posIS = null;

        dictIS = getResource(DICT_FILENAME_SUFFIX);
        // no buffering here, as we load in one large buffer
        in = new InputStreamDataInput(dictIS);
        CodecUtil.checkHeader(in, DICT_HEADER, VERSION, VERSION);
        final int size = in.readVInt();
        final ByteBuffer tmpBuffer = ByteBuffer.allocateDirect(size);
        final ReadableByteChannel channel = Channels.newChannel(dictIS);
        final int read = channel.read(tmpBuffer);
        if (read != size) {
            throw new EOFException("Cannot read whole dictionary");
        }
        dictIS.close();
        dictIS = null;
        buffer = tmpBuffer.asReadOnlyBuffer();
        success = true;
    } finally {
        if (success) {
            IOUtils.close(mapIS, posIS, dictIS);
        } else {
            IOUtils.closeWhileHandlingException(mapIS, posIS, dictIS);
        }
    }

    this.targetMap = targetMap;
    this.targetMapOffsets = targetMapOffsets;
    this.posDict = posDict;
    this.inflTypeDict = inflTypeDict;
    this.inflFormDict = inflFormDict;
    this.buffer = buffer;
}