當前位置: 首頁>>代碼示例>>Java>>正文


Java StreamInput.readBytes方法代碼示例

本文整理匯總了Java中org.elasticsearch.common.io.stream.StreamInput.readBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamInput.readBytes方法的具體用法?Java StreamInput.readBytes怎麽用?Java StreamInput.readBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.common.io.stream.StreamInput的用法示例。


在下文中一共展示了StreamInput.readBytes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: AbstractInternalHDRPercentiles

import org.elasticsearch.common.io.stream.StreamInput; //導入方法依賴的package包/類
/**
 * Read from a stream.
 */
protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException {
    super(in);
    format = in.readNamedWriteable(DocValueFormat.class);
    keys = in.readDoubleArray();
    long minBarForHighestToLowestValueRatio = in.readLong();
    final int serializedLen = in.readVInt();
    byte[] bytes = new byte[serializedLen];
    in.readBytes(bytes, 0, serializedLen);
    ByteBuffer stateBuffer = ByteBuffer.wrap(bytes);
    try {
        state = DoubleHistogram.decodeFromCompressedByteBuffer(stateBuffer, minBarForHighestToLowestValueRatio);
    } catch (DataFormatException e) {
        throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e);
    }
    keyed = in.readBoolean();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:AbstractInternalHDRPercentiles.java

示例2: doReadFrom

import org.elasticsearch.common.io.stream.StreamInput; //導入方法依賴的package包/類
@Override
protected void doReadFrom(StreamInput in) throws IOException {
    valueFormatter = ValueFormatterStreams.readOptional(in);
    keys = new double[in.readInt()];
    for (int i = 0; i < keys.length; ++i) {
        keys[i] = in.readDouble();
    }
    long minBarForHighestToLowestValueRatio = in.readLong();
    final int serializedLen = in.readVInt();
    byte[] bytes = new byte[serializedLen];
    in.readBytes(bytes, 0, serializedLen);
    ByteBuffer stateBuffer = ByteBuffer.wrap(bytes);
    try {
        state = DoubleHistogram.decodeFromCompressedByteBuffer(stateBuffer, minBarForHighestToLowestValueRatio);
    } catch (DataFormatException e) {
        throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e);
    }
    keyed = in.readBoolean();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:20,代碼來源:AbstractInternalHDRPercentiles.java

示例3: testStreamInput

import org.elasticsearch.common.io.stream.StreamInput; //導入方法依賴的package包/類
public void testStreamInput() throws IOException {
    int length = randomIntBetween(10, scaledRandomIntBetween(PAGE_SIZE * 2, PAGE_SIZE * 20));
    BytesReference pbr = newBytesReference(length);
    StreamInput si = pbr.streamInput();
    assertNotNull(si);

    // read single bytes one by one
    assertEquals(pbr.get(0), si.readByte());
    assertEquals(pbr.get(1), si.readByte());
    assertEquals(pbr.get(2), si.readByte());

    // reset the stream for bulk reading
    si.reset();

    // buffer for bulk reads
    byte[] origBuf = new byte[length];
    random().nextBytes(origBuf);
    byte[] targetBuf = Arrays.copyOf(origBuf, origBuf.length);

    // bulk-read 0 bytes: must not modify buffer
    si.readBytes(targetBuf, 0, 0);
    assertEquals(origBuf[0], targetBuf[0]);
    si.reset();

    // read a few few bytes as ints
    int bytesToRead = randomIntBetween(1, length / 2);
    for (int i = 0; i < bytesToRead; i++) {
        int b = si.read();
        assertEquals(pbr.get(i) & 0xff, b);
    }
    si.reset();

    // bulk-read all
    si.readFully(targetBuf);
    assertArrayEquals(BytesReference.toBytes(pbr), targetBuf);

    // continuing to read should now fail with EOFException
    try {
        si.readByte();
        fail("expected EOF");
    } catch (EOFException | IndexOutOfBoundsException eof) {
        // yay
    }

    // try to read more than the stream contains
    si.reset();
    expectThrows(IndexOutOfBoundsException.class, () ->
        si.readBytes(targetBuf, 0, length * 2));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:50,代碼來源:AbstractBytesReferenceTestCase.java

示例4: readCompressedString

import org.elasticsearch.common.io.stream.StreamInput; //導入方法依賴的package包/類
public static CompressedXContent readCompressedString(StreamInput in) throws IOException {
    int crc32 = in.readInt();
    byte[] compressed = new byte[in.readVInt()];
    in.readBytes(compressed, 0, compressed.length);
    return new CompressedXContent(compressed, crc32);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:7,代碼來源:CompressedXContent.java


注:本文中的org.elasticsearch.common.io.stream.StreamInput.readBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。