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

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

Introduction

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

Prototype

public byte[] bytes() 

Source Link

Document

Return a reference to the bytes of this builder.

Usage

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

License:Apache License

public static void checkFooter(ChecksumIndexInput input) throws IOException {
    BytesRefBuilder scratch = new BytesRefBuilder();
    String expectedChecksum = String.format(Locale.ROOT, "%020d", input.getChecksum());
    ONSQLUtil.readLine(input, scratch);/*from www .j  a va 2  s .c om*/
    if (StringHelper.startsWith(scratch.get(), CHECKSUM) == false) {
        throw new CorruptIndexException("ONSQL failure: expected checksum line but got "
                + scratch.get().utf8ToString() + " (resource=" + input + ")");
    }
    String actualChecksum = new BytesRef(scratch.bytes(), CHECKSUM.length, scratch.length() - CHECKSUM.length)
            .utf8ToString();
    if (!expectedChecksum.equals(actualChecksum)) {
        throw new CorruptIndexException("ONSQL checksum failure: " + actualChecksum + " != " + expectedChecksum
                + " (resource=" + input + ")");
    }
    if (input.length() != input.getFilePointer()) {
        throw new CorruptIndexException(
                "Unexpected stuff at the end of file, please be careful with your text editor! (resource="
                        + input + ")");
    }
}

From source file:org.apache.solr.schema.DatePointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    Date date = (Date) toNativeType(val.toString());
    result.grow(Long.BYTES);/* ww w.j a  v  a2 s .c o  m*/
    result.setLength(Long.BYTES);
    LongPoint.encodeDimension(date.getTime(), result.bytes(), 0);
}

From source file:org.apache.solr.schema.DoublePointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    result.grow(Double.BYTES);//from w  w  w. ja va  2  s  .c o m
    result.setLength(Double.BYTES);
    DoublePoint.encodeDimension(Double.parseDouble(val.toString()), result.bytes(), 0);
}

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    final String s = val.toString();
    if (s == null)
        return;/* ww  w.jav  a  2 s. c o  m*/

    result.grow(Integer.BYTES);
    result.setLength(Integer.BYTES);
    final Integer intValue = enumMapping.stringValueToIntValue(s);
    NumericUtils.intToSortableBytes(intValue, result.bytes(), 0);
}

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public String storedToIndexed(IndexableField f) {
    final Number val = f.numericValue();
    if (val == null)
        return null;
    final BytesRefBuilder bytes = new BytesRefBuilder();
    bytes.grow(Integer.BYTES);//from w  ww  .ja  v  a2s .c o m
    bytes.setLength(Integer.BYTES);
    NumericUtils.intToSortableBytes(val.intValue(), bytes.bytes(), 0);
    return bytes.get().utf8ToString();
}

From source file:org.apache.solr.schema.FloatPointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    result.grow(Float.BYTES);/*from  ww w .  j  a v a  2 s  . c o  m*/
    result.setLength(Float.BYTES);
    FloatPoint.encodeDimension(Float.parseFloat(val.toString()), result.bytes(), 0);
}

From source file:org.apache.solr.schema.IntPointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    result.grow(Integer.BYTES);/*ww  w.j  a v a2 s  . c  om*/
    result.setLength(Integer.BYTES);
    IntPoint.encodeDimension(Integer.parseInt(val.toString()), result.bytes(), 0);
}

From source file:org.apache.solr.schema.LongPointField.java

License:Apache License

@Override
public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
    result.grow(Long.BYTES);/*from   w  ww .  ja va2s  . c  o  m*/
    result.setLength(Long.BYTES);
    LongPoint.encodeDimension(Long.parseLong(val.toString()), result.bytes(), 0);
}

From source file:org.codelibs.elasticsearch.common.Strings.java

License:Apache License

public static byte[] toUTF8Bytes(CharSequence charSequence, BytesRefBuilder spare) {
    spare.copyChars(charSequence);/* w w w  . j a  va 2 s . c  o  m*/
    return Arrays.copyOf(spare.bytes(), spare.length());
}

From source file:org.elasticsearch.common.blobstore.BlobStoreTests.java

License:Apache License

@Test
public void testWriteRead() throws IOException {
    final BlobStore store = newBlobStore();
    final BlobContainer container = store.blobContainer(new BlobPath());
    byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
    container.writeBlob("foobar", new BytesArray(data));
    try (InputStream stream = container.readBlob("foobar")) {
        BytesRefBuilder target = new BytesRefBuilder();
        while (target.length() < data.length) {
            byte[] buffer = new byte[scaledRandomIntBetween(1, data.length - target.length())];
            int offset = scaledRandomIntBetween(0, buffer.length - 1);
            int read = stream.read(buffer, offset, buffer.length - offset);
            target.append(new BytesRef(buffer, offset, read));
        }/*  w w  w .j a va  2 s  .co m*/
        assertEquals(data.length, target.length());
        assertArrayEquals(data, Arrays.copyOfRange(target.bytes(), 0, target.length()));
    }
    store.close();
}