当前位置: 首页>>代码示例>>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;未经允许,请勿转载。