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


Java DataOutputBuffer.toByteArray方法代码示例

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


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

示例1: testSerialization

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerialization() throws Exception
{
    Range<Token> full = new Range<>(tok(-1), tok(-1));

    // populate and validate the tree
    mt.maxsize(256);
    mt.init();
    for (TreeRange range : mt.invalids())
        range.addAll(new HIterator(range.right));

    byte[] initialhash = mt.hash(full);

    DataOutputBuffer out = new DataOutputBuffer();
    MerkleTree.serializer.serialize(mt, out, MessagingService.current_version);
    byte[] serialized = out.toByteArray();

    ByteArrayDataInput in = ByteStreams.newDataInput(serialized);
    MerkleTree restored = MerkleTree.serializer.deserialize(in, MessagingService.current_version);

    assertHashEquals(initialhash, restored.hash(full));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:23,代码来源:MerkleTreeTest.java

示例2: testSerialization

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerialization() throws IOException
{
    Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1);
    DataOutputBuffer dos = new DataOutputBuffer();
    IndexSummary.serializer.serialize(random.right, dos, false);
    // write junk
    dos.writeUTF("JUNK");
    dos.writeUTF("JUNK");
    FileUtils.closeQuietly(dos);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
    IndexSummary is = IndexSummary.serializer.deserialize(dis, DatabaseDescriptor.getPartitioner(), false, 1, 1);
    for (int i = 0; i < 100; i++)
        assertEquals(i, is.binarySearch(random.left.get(i)));
    // read the junk
    assertEquals(dis.readUTF(), "JUNK");
    assertEquals(dis.readUTF(), "JUNK");
    is.close();
    FileUtils.closeQuietly(dis);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:21,代码来源:IndexSummaryTest.java

示例3: testAddEmptyKey

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testAddEmptyKey() throws Exception
{
    IPartitioner p = new RandomPartitioner();
    try (IndexSummaryBuilder builder = new IndexSummaryBuilder(1, 1, BASE_SAMPLING_LEVEL))
    {
        builder.maybeAddEntry(p.decorateKey(ByteBufferUtil.EMPTY_BYTE_BUFFER), 0);
        IndexSummary summary = builder.build(p);
        assertEquals(1, summary.size());
        assertEquals(0, summary.getPosition(0));
        assertArrayEquals(new byte[0], summary.getKey(0));

        DataOutputBuffer dos = new DataOutputBuffer();
        IndexSummary.serializer.serialize(summary, dos, false);
        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
        IndexSummary loaded = IndexSummary.serializer.deserialize(dis, p, false, 1, 1);

        assertEquals(1, loaded.size());
        assertEquals(summary.getPosition(0), loaded.getPosition(0));
        assertArrayEquals(summary.getKey(0), summary.getKey(0));
        summary.close();
        loaded.close();
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:25,代码来源:IndexSummaryTest.java

示例4: testSerialization

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerialization() throws Exception
{
    Range<Token> full = new Range<>(tok(-1), tok(-1));

    // populate and validate the tree
    mt.maxsize(256);
    mt.init();
    for (TreeRange range : mt.invalids())
        range.addAll(new HIterator(range.right));

    byte[] initialhash = mt.hash(full);

    DataOutputBuffer out = new DataOutputBuffer();
    MerkleTree.serializer.serialize(mt, out, MessagingService.current_version);
    byte[] serialized = out.toByteArray();

    DataInputPlus in = new DataInputBuffer(serialized);
    MerkleTree restored = MerkleTree.serializer.deserialize(in, MessagingService.current_version);

    assertHashEquals(initialhash, restored.hash(full));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:23,代码来源:MerkleTreeTest.java

示例5: testSerialization

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerialization() throws IOException
{
    Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1);
    DataOutputBuffer dos = new DataOutputBuffer();
    IndexSummary.serializer.serialize(random.right, dos, false);
    // write junk
    dos.writeUTF("JUNK");
    dos.writeUTF("JUNK");
    FileUtils.closeQuietly(dos);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
    IndexSummary is = IndexSummary.serializer.deserialize(dis, partitioner, false, 1, 1);
    for (int i = 0; i < 100; i++)
        assertEquals(i, is.binarySearch(random.left.get(i)));
    // read the junk
    assertEquals(dis.readUTF(), "JUNK");
    assertEquals(dis.readUTF(), "JUNK");
    is.close();
    FileUtils.closeQuietly(dis);
    random.right.close();
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:22,代码来源:IndexSummaryTest.java

示例6: testSerialization

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerialization() throws IOException
{
    Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1);
    DataOutputBuffer dos = new DataOutputBuffer();
    IndexSummary.serializer.serialize(random.right, dos, false);
    // write junk
    dos.writeUTF("JUNK");
    dos.writeUTF("JUNK");
    FileUtils.closeQuietly(dos);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
    IndexSummary is = IndexSummary.serializer.deserialize(dis, DatabaseDescriptor.getPartitioner(), false, 1, 1);
    for (int i = 0; i < 100; i++)
        assertEquals(i, is.binarySearch(random.left.get(i)));
    // read the junk
    assertEquals(dis.readUTF(), "JUNK");
    assertEquals(dis.readUTF(), "JUNK");
    FileUtils.closeQuietly(dis);
}
 
开发者ID:daidong,项目名称:GraphTrek,代码行数:20,代码来源:IndexSummaryTest.java

示例7: testAddEmptyKey

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testAddEmptyKey() throws Exception
{
    IPartitioner p = new RandomPartitioner();
    IndexSummaryBuilder builder = new IndexSummaryBuilder(1, 1, BASE_SAMPLING_LEVEL);
    builder.maybeAddEntry(p.decorateKey(ByteBufferUtil.EMPTY_BYTE_BUFFER), 0);
    IndexSummary summary = builder.build(p);
    assertEquals(1, summary.size());
    assertEquals(0, summary.getPosition(0));
    assertArrayEquals(new byte[0], summary.getKey(0));

    DataOutputBuffer dos = new DataOutputBuffer();
    IndexSummary.serializer.serialize(summary, dos, false);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
    IndexSummary loaded = IndexSummary.serializer.deserialize(dis, p, false, 1, 1);

    assertEquals(1, loaded.size());
    assertEquals(summary.getPosition(0), loaded.getPosition(0));
    assertArrayEquals(summary.getKey(0), summary.getKey(0));
}
 
开发者ID:daidong,项目名称:GraphTrek,代码行数:21,代码来源:IndexSummaryTest.java

示例8: testSerDe

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerDe() throws Exception
{
    StreamingHistogram hist = new StreamingHistogram(5);
    long[] samples = new long[]{23, 19, 10, 16, 36, 2, 9};

    // add 7 points to histogram of 5 bins
    for (int i = 0; i < samples.length; i++)
    {
        hist.update(samples[i]);
    }

    DataOutputBuffer out = new DataOutputBuffer();
    StreamingHistogram.serializer.serialize(hist, out);
    byte[] bytes = out.toByteArray();

    StreamingHistogram deserialized = StreamingHistogram.serializer.deserialize(new DataInputStream(new ByteArrayInputStream(bytes)));

    // deserialized histogram should have following values
    Map<Double, Long> expected1 = new LinkedHashMap<Double, Long>(5);
    expected1.put(2.0, 1L);
    expected1.put(9.5, 2L);
    expected1.put(17.5, 2L);
    expected1.put(23.0, 1L);
    expected1.put(36.0, 1L);

    Iterator<Map.Entry<Double, Long>> expectedItr = expected1.entrySet().iterator();
    for (Map.Entry<Double, Long> actual : deserialized.getAsMap().entrySet())
    {
        Map.Entry<Double, Long> entry = expectedItr.next();
        assertEquals(entry.getKey(), actual.getKey(), 0.01);
        assertEquals(entry.getValue(), actual.getValue());
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:35,代码来源:StreamingHistogramTest.java

示例9: testSerialization

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerialization() throws Exception
{
    Range<Token> first = new Range<>(tok(3), tok(4));

    Collection<Range<Token>> ranges = new ArrayList<>();

    ranges.add(first);
    ranges.add(new Range<Token>(tok(5), tok(2)));

    mts = new MerkleTrees(partitioner);
    mts.addMerkleTrees(256, ranges);

    // populate and validate the tree
    mts.init();
    for (TreeRange range : mts.invalids())
        range.addAll(new HIterator(range.right));

    byte[] initialhash = mts.hash(first);

    long serializedSize = MerkleTrees.serializer.serializedSize(mts, MessagingService.current_version);
    DataOutputBuffer out = new DataOutputBuffer();
    MerkleTrees.serializer.serialize(mts, out, MessagingService.current_version);
    byte[] serialized = out.toByteArray();

    assertEquals(serializedSize, serialized.length);

    DataInputBuffer in = new DataInputBuffer(serialized);
    MerkleTrees restored = MerkleTrees.serializer.deserialize(in, MessagingService.current_version);

    assertHashEquals(initialhash, restored.hash(first));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:33,代码来源:MerkleTreesTest.java

示例10: testSerDe

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
@Test
public void testSerDe() throws Exception
{
    StreamingHistogram hist = new StreamingHistogram(5);
    long[] samples = new long[]{23, 19, 10, 16, 36, 2, 9};

    // add 7 points to histogram of 5 bins
    for (int i = 0; i < samples.length; i++)
    {
        hist.update(samples[i]);
    }

    DataOutputBuffer out = new DataOutputBuffer();
    StreamingHistogram.serializer.serialize(hist, out);
    byte[] bytes = out.toByteArray();

    StreamingHistogram deserialized = StreamingHistogram.serializer.deserialize(new DataInputBuffer(bytes));

    // deserialized histogram should have following values
    Map<Double, Long> expected1 = new LinkedHashMap<Double, Long>(5);
    expected1.put(2.0, 1L);
    expected1.put(9.5, 2L);
    expected1.put(17.5, 2L);
    expected1.put(23.0, 1L);
    expected1.put(36.0, 1L);

    Iterator<Map.Entry<Double, Long>> expectedItr = expected1.entrySet().iterator();
    for (Map.Entry<Double, Long> actual : deserialized.getAsMap().entrySet())
    {
        Map.Entry<Double, Long> entry = expectedItr.next();
        assertEquals(entry.getKey(), actual.getKey(), 0.01);
        assertEquals(entry.getValue(), actual.getValue());
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:35,代码来源:StreamingHistogramTest.java

示例11: serializeDescriptor

import org.apache.cassandra.io.util.DataOutputBuffer; //导入方法依赖的package包/类
private static byte[] serializeDescriptor(HintsDescriptor descriptor) throws IOException
{
    DataOutputBuffer dob = new DataOutputBuffer();
    descriptor.serialize(dob);
    return dob.toByteArray();
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:7,代码来源:HintsDescriptorTest.java


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