当前位置: 首页>>代码示例>>Java>>正文


Java ReleasableBytesStreamOutput.writeByte方法代码示例

本文整理汇总了Java中org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput.writeByte方法的典型用法代码示例。如果您正苦于以下问题:Java ReleasableBytesStreamOutput.writeByte方法的具体用法?Java ReleasableBytesStreamOutput.writeByte怎么用?Java ReleasableBytesStreamOutput.writeByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput的用法示例。


在下文中一共展示了ReleasableBytesStreamOutput.writeByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRandomizedBytesReference

import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; //导入方法依赖的package包/类
private BytesReference getRandomizedBytesReference(int length) throws IOException {
    // we know bytes stream output always creates a paged bytes reference, we use it to create randomized content
    ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(length, bigarrays);
    for (int i = 0; i < length; i++) {
        out.writeByte((byte) random().nextInt(1 << 8));
    }
    assertEquals(out.size(), length);
    BytesReference ref = out.bytes();
    assertEquals(ref.length(), length);
    if (randomBoolean()) {
        return new BytesArray(ref.toBytesRef());
    } else if (randomBoolean()) {
        BytesRef bytesRef = ref.toBytesRef();
        return Netty4Utils.toBytesReference(Unpooled.wrappedBuffer(bytesRef.bytes, bytesRef.offset,
            bytesRef.length));
    } else {
        return ref;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:Netty4UtilsTests.java

示例2: newBytesReference

import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; //导入方法依赖的package包/类
@Override
protected BytesReference newBytesReference(int length) throws IOException {
    ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(length, bigarrays);
    for (int i = 0; i < length; i++) {
        out.writeByte((byte) random().nextInt(1 << 8));
    }
    assertEquals(out.size(), length);
    BytesReference ref = out.bytes();
    assertEquals(ref.length(), length);
    BytesRef bytesRef = ref.toBytesRef();
    final ByteBuf buffer = Unpooled.wrappedBuffer(bytesRef.bytes, bytesRef.offset, bytesRef.length);
    return Netty4Utils.toBytesReference(buffer);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:ByteBufBytesReferenceTests.java

示例3: newBytesReference

import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; //导入方法依赖的package包/类
protected BytesReference newBytesReference(int length) throws IOException {
    // we know bytes stream output always creates a paged bytes reference, we use it to create randomized content
    ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(length, bigarrays);
    for (int i = 0; i < length; i++) {
        out.writeByte((byte) random().nextInt(1 << 8));
    }
    assertThat(out.size(), Matchers.equalTo(length));
    BytesReference ref = out.bytes();
    assertThat(ref.length(), Matchers.equalTo(length));
    assertThat(ref, Matchers.instanceOf(PagedBytesReference.class));
    return ref;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:PagedBytesReferenceTests.java

示例4: newRefList

import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; //导入方法依赖的package包/类
private List<BytesReference> newRefList(int length) throws IOException {
    List<BytesReference> referenceList = new ArrayList<>();
    for (int i = 0; i < length;) {
        int remaining = length-i;
        int sliceLength = randomIntBetween(1, remaining);
        ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(sliceLength, bigarrays);
        for (int j = 0; j < sliceLength; j++) {
            out.writeByte((byte) random().nextInt(1 << 8));
        }
        assertEquals(sliceLength, out.size());
        referenceList.add(out.bytes());
        i+=sliceLength;
    }
    return referenceList;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:CompositeBytesReferenceTests.java

示例5: testCompareTo

import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; //导入方法依赖的package包/类
public void testCompareTo() throws IOException {
    final int iters = randomIntBetween(5, 10);
    for (int i = 0; i < iters; i++) {
        int length = randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 8));
        BytesReference bytesReference = newBytesReference(length);
        assertTrue(bytesReference.compareTo(new BytesArray("")) > 0);
        assertTrue(new BytesArray("").compareTo(bytesReference) < 0);


        assertEquals(0, bytesReference.compareTo(bytesReference));
        int sliceFrom = randomIntBetween(0, bytesReference.length());
        int sliceLength = randomIntBetween(0, bytesReference.length() - sliceFrom);
        BytesReference slice = bytesReference.slice(sliceFrom, sliceLength);

        assertEquals(bytesReference.toBytesRef().compareTo(slice.toBytesRef()),
            new BytesArray(bytesReference.toBytesRef(), true).compareTo(new BytesArray(slice.toBytesRef(), true)));

        assertEquals(bytesReference.toBytesRef().compareTo(slice.toBytesRef()),
            bytesReference.compareTo(slice));
        assertEquals(slice.toBytesRef().compareTo(bytesReference.toBytesRef()),
            slice.compareTo(bytesReference));

        assertEquals(0, slice.compareTo(new BytesArray(slice.toBytesRef())));
        assertEquals(0, new BytesArray(slice.toBytesRef()).compareTo(slice));

        final int crazyLength = length + randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 8));
        ReleasableBytesStreamOutput crazyStream = new ReleasableBytesStreamOutput(length, bigarrays);
        final int offset = randomIntBetween(0, crazyLength - length);
        for (int j = 0; j < offset; j++) {
            crazyStream.writeByte((byte) random().nextInt(1 << 8));
        }
        bytesReference.writeTo(crazyStream);
        for (int j = crazyStream.size(); j < crazyLength; j++) {
            crazyStream.writeByte((byte) random().nextInt(1 << 8));
        }
        PagedBytesReference crazyReference = crazyStream.bytes();

        assertFalse(crazyReference.compareTo(bytesReference) == 0);
        assertEquals(0, crazyReference.slice(offset, length).compareTo(
            bytesReference));
        assertEquals(0, bytesReference.compareTo(
            crazyReference.slice(offset, length)));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:AbstractBytesReferenceTestCase.java


注:本文中的org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput.writeByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。