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

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

Introduction

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

Prototype

public ByteArrayDataInput(byte[] bytes) 

Source Link

Usage

From source file:elhuyar.bilakit.Stemmer.java

License:Apache License

/**
 * Constructs a new Stemmer which will use the provided Dictionary to create its stems.
 *
 * @param dictionary Dictionary that will be used to create the stems
 *//*w  w w  .jav a  2 s .  c  om*/
public Stemmer(Dictionary dictionary) {
    this.dictionary = dictionary;
    this.affixReader = new ByteArrayDataInput(dictionary.affixData);
    for (int level = 0; level < 3; level++) {
        if (dictionary.prefixes != null) {
            prefixArcs[level] = new FST.Arc<>();
            prefixReaders[level] = dictionary.prefixes.getBytesReader();
        }
        if (dictionary.suffixes != null) {
            suffixArcs[level] = new FST.Arc<>();
            suffixReaders[level] = dictionary.suffixes.getBytesReader();
        }
    }
    formStep = dictionary.hasStemExceptions ? 2 : 1;
}

From source file:org.elasticsearch.common.util.ByteUtilsTests.java

License:Apache License

public void testVLong() throws IOException {
    final long[] data = new long[atLeast(1000)];
    for (int i = 0; i < data.length; ++i) {
        switch (randomInt(4)) {
        case 0:/*from   w w  w.  java 2  s  .c  om*/
            data[i] = 0;
            break;
        case 1:
            data[i] = Long.MAX_VALUE;
            break;
        case 2:
            data[i] = Long.MIN_VALUE;
            break;
        case 3:
            data[i] = randomInt(1 << randomIntBetween(2, 30));
            break;
        case 4:
            data[i] = randomLong();
            break;
        default:
            throw new AssertionError();
        }
    }
    final byte[] encoded = new byte[ByteUtils.MAX_BYTES_VLONG * data.length];
    ByteArrayDataOutput out = new ByteArrayDataOutput(encoded);
    for (int i = 0; i < data.length; ++i) {
        final int pos = out.getPosition();
        ByteUtils.writeVLong(out, data[i]);
        if (data[i] < 0) {
            assertEquals(ByteUtils.MAX_BYTES_VLONG, out.getPosition() - pos);
        }
    }
    final ByteArrayDataInput in = new ByteArrayDataInput(encoded);
    for (int i = 0; i < data.length; ++i) {
        assertEquals(data[i], ByteUtils.readVLong(in));
    }
}

From source file:org.sindice.siren.index.codecs.siren10.Siren10PostingsReader.java

License:Apache License

@Override
public void readTermsBlock(final IndexInput termsIn, final FieldInfo fieldInfo, final BlockTermState _termState)
        throws IOException {
    final Siren10TermState termState = (Siren10TermState) _termState;

    final int len = termsIn.readVInt();

    if (termState.bytes == null) {
        termState.bytes = new byte[ArrayUtil.oversize(len, 1)];
        termState.bytesReader = new ByteArrayDataInput(termState.bytes);
    } else if (termState.bytes.length < len) {
        termState.bytes = new byte[ArrayUtil.oversize(len, 1)];
    }/*  ww w .  j a v  a2s .  c o m*/

    termState.bytesReader.reset(termState.bytes, 0, len);
    termsIn.readBytes(termState.bytes, 0, len);
}

From source file:stemmer.Stemmer.java

License:Apache License

/**
 * Constructs a new Stemmer which will use the provided Dictionary to create its stems.
 *
 * @param dictionary Dictionary that will be used to create the stems
 *//*from  w w  w  .  j  a  v a 2s .c o m*/
public Stemmer(Dictionary dictionary) {
    this.dictionary = dictionary;
    this.affixReader = new ByteArrayDataInput(dictionary.affixData);
    for (int level = 0; level < 3; level++) {
        if (dictionary.prefixes != null) {
            prefixArcs[level] = new FST.Arc<>();
            prefixReaders[level] = dictionary.prefixes.getBytesReader();
        }
        if (dictionary.suffixes != null) {
            suffixArcs[level] = new FST.Arc<>();
            suffixReaders[level] = dictionary.suffixes.getBytesReader();
        }
    }
}