ByteArrayDataOutput toByteArray - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ByteArrayDataOutput toByteArray method.

This code example shows how to use the following methods:toByteArray, writeByte
	} 
 
	public final Packet makePacket() 
	{ 
		ByteArrayDataOutput out = ByteStreams.newDataOutput();
		out.writeByte(getPacketId());
		write(out);
		return PacketDispatcher.getPacket(CHANNEL, out.toByteArray());
	} 
 
	public abstract void write(ByteArrayDataOutput out);
 
	public abstract void read(ByteArrayDataInput in) throws ProtocolException;
 
	public abstract void execute(EntityPlayer player, Side side) throws ProtocolException;
} 
5
CodeRank
This code example shows how to use the following methods:toByteArray
  @SuppressWarnings("deprecation") 
  private void verifyDecodingSupportsV1(TransactionEdit edit) throws IOException {
    TransactionEdit.TransactionEditCodecV1 v1Codec = new TransactionEdit.TransactionEditCodecV1();
    // encoding with codec of v1 
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    v1Codec.encode(edit, out);
 
    // decoding 
    TransactionEdit decodedEdit = new TransactionEdit();
    DataInput in = ByteStreams.newDataInput(out.toByteArray());
    decodedEdit.readFields(in);
 
    Assert.assertEquals(edit, decodedEdit);
  } 
} 
5
CodeRank
This code example shows how to use the following methods:toByteArray
    } 
 
    public void testLong(long l) throws IOException {
        final VarULongSerializer serializer = new VarULongSerializer();
        final ByteArrayDataOutput out = ByteStreams.newDataOutput();
        serializer.write(l, out);
        assertEquals(l, serializer.read(ByteStreams.newDataInput(out.toByteArray())).longValue());
    } 
 
    public void testInt(int i) throws IOException {
        final VarULongSerializer serializer = new VarULongSerializer();
        final ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeInt(i);
        assertEquals(i, serializer.read(ByteStreams.newDataInput(out.toByteArray())).longValue());
    } 
} 
5
CodeRank
This code example shows how to use the following methods:toByteArray
import java.io.IOException;
 
public class JournalUtil { 
  public static byte[] locationToBytes(Location location) throws IOException {
    ByteArrayDataOutput dos = ByteStreams.newDataOutput();
    location.writeExternal(dos);
    return dos.toByteArray();
  } 
 
  public static Journal createJournal(String dirPath, int fileSize, int writeBatchSize) {
    Journal journal = new Journal();
    File directory = new File(dirPath);
    //noinspection ResultOfMethodCallIgnored 
    directory.mkdirs();
    journal.setDirectory(directory);
    journal.setMaxFileLength(fileSize);
    journal.setMaxWriteBatchSize(writeBatchSize);
 
    try { 
      journal.open();
5
CodeRank
This code example shows how to use the following methods:toByteArray
    public void testSerialization() throws Exception {
        final Broker broker = new Broker("127.0.0.1", 9092, 1);
        final Partition partition = new Partition("topic_name", 0, broker);
        final KafkaInputSplit split = new KafkaInputSplit(partition, 0, 10l, false);
        final ByteArrayDataOutput out = ByteStreams.newDataOutput();
        split.write(out);
 
        final KafkaInputSplit actual = new KafkaInputSplit();
        actual.readFields(ByteStreams.newDataInput(out.toByteArray()));
 
        assertEquals(split, actual);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:toByteArray
  } 
 
  private static byte[] toBytes(ConsumerConfig consumerConfig) throws IOException {
    ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
    write(dataOutput, consumerConfig);
    return dataOutput.toByteArray();
  } 
 
  public static void write(DataOutput dataOutput, ConsumerConfig consumerConfig) throws IOException {
    dataOutput.writeLong(consumerConfig.getGroupId());
    dataOutput.writeInt(consumerConfig.getGroupSize());
    dataOutput.writeInt(consumerConfig.getInstanceId());
    WritableUtils.writeEnum(dataOutput, consumerConfig.getDequeueStrategy());
    WritableUtils.writeString(dataOutput, consumerConfig.getHashKey());
  } 
 
  private static ConsumerConfig bytesToConsumerConfig(byte[] bytes) throws IOException {
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(bytes);
    return readConsumerConfig(dataInput);
  } 
3
CodeRank