Example usage for org.apache.lucene.util BytesRefBuilder setByteAt

List of usage examples for org.apache.lucene.util BytesRefBuilder setByteAt

Introduction

In this page you can find the example usage for org.apache.lucene.util BytesRefBuilder setByteAt.

Prototype

public void setByteAt(int offset, byte b) 

Source Link

Document

Set a byte.

Usage

From source file:org.apache.solr.codecs.onsql.ONSQLUtil.java

License:Apache License

public static void readLine(DataInput in, BytesRefBuilder scratch) throws IOException {
    int upto = 0;
    while (true) {
        byte b = in.readByte();
        scratch.grow(1 + upto);//  www. ja v a2 s .  co  m
        if (b == ESCAPE) {
            scratch.setByteAt(upto++, in.readByte());
        } else {
            if (b == NEWLINE) {
                break;
            } else {
                scratch.setByteAt(upto++, b);
            }
        }
    }
    scratch.setLength(upto);
}

From source file:org.apache.solr.legacy.LegacyNumericUtils.java

License:Apache License

/**
 * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
 * This is method is used by {@link org.apache.solr.legacy.LegacyNumericTokenStream}.
 * After encoding, {@code bytes.offset} will always be 0. 
 * @param val the numeric value//from ww  w  . j  a  v a  2 s.  c  om
 * @param shift how many bits to strip from the right
 * @param bytes will contain the encoded value
 */
public static void longToPrefixCoded(final long val, final int shift, final BytesRefBuilder bytes) {
    // ensure shift is 0..63
    if ((shift & ~0x3f) != 0) {
        throw new IllegalArgumentException("Illegal shift value, must be 0..63; got shift=" + shift);
    }
    int nChars = (((63 - shift) * 37) >> 8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63
    bytes.setLength(nChars + 1); // one extra for the byte that contains the shift info
    bytes.grow(BUF_SIZE_LONG);
    bytes.setByteAt(0, (byte) (SHIFT_START_LONG + shift));
    long sortableBits = val ^ 0x8000000000000000L;
    sortableBits >>>= shift;
    while (nChars > 0) {
        // Store 7 bits per byte for compatibility
        // with UTF-8 encoding of terms
        bytes.setByteAt(nChars--, (byte) (sortableBits & 0x7f));
        sortableBits >>>= 7;
    }
}

From source file:org.apache.solr.legacy.LegacyNumericUtils.java

License:Apache License

/**
 * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
 * This is method is used by {@link org.apache.solr.legacy.LegacyNumericTokenStream}.
 * After encoding, {@code bytes.offset} will always be 0.
 * @param val the numeric value/*from   w  w w  .  j  a va  2 s . c o  m*/
 * @param shift how many bits to strip from the right
 * @param bytes will contain the encoded value
 */
public static void intToPrefixCoded(final int val, final int shift, final BytesRefBuilder bytes) {
    // ensure shift is 0..31
    if ((shift & ~0x1f) != 0) {
        throw new IllegalArgumentException("Illegal shift value, must be 0..31; got shift=" + shift);
    }
    int nChars = (((31 - shift) * 37) >> 8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63
    bytes.setLength(nChars + 1); // one extra for the byte that contains the shift info
    bytes.grow(LegacyNumericUtils.BUF_SIZE_LONG); // use the max
    bytes.setByteAt(0, (byte) (SHIFT_START_INT + shift));
    int sortableBits = val ^ 0x80000000;
    sortableBits >>>= shift;
    while (nChars > 0) {
        // Store 7 bits per byte for compatibility
        // with UTF-8 encoding of terms
        bytes.setByteAt(nChars--, (byte) (sortableBits & 0x7f));
        sortableBits >>>= 7;
    }
}

From source file:perf.AutoPrefixPerf.java

License:Apache License

private static void longToBytes(long v, BytesRefBuilder token) {
    // Like NumericUtils.longToPrefixCodedBytes, but without the
    // prefix byte, and fully binary encoding (not 7 bit clean):
    long sortableBits = v ^ 0x8000000000000000L;
    int index = 7;
    while (index >= 0) {
        token.setByteAt(index, (byte) (sortableBits & 0xffL));
        index--;/* www . j a va2 s. co m*/
        sortableBits >>>= 8;
    }
}