當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。