Пример #1
0
  private byte[] writePartialFile(DataOutputStream out) throws IOException {
    MessageQueue.Message m1 =
        MessageQueue.Message.newBuilder()
            .setTime(1)
            .setPayload(ByteString.copyFromUtf8("test 1"))
            .build();

    out.writeInt(m1.getSerializedSize());
    m1.writeTo(out);

    MessageQueue.Message m2 =
        MessageQueue.Message.newBuilder()
            .setTime(2)
            .setPayload(ByteString.copyFromUtf8("test 2"))
            .build();

    out.writeInt(m2.getSerializedSize());
    m2.writeTo(out);

    MessageQueue.Message m3 =
        MessageQueue.Message.newBuilder()
            .setTime(3)
            .setPayload(ByteString.copyFromUtf8("test 3"))
            .build();

    byte[] bytes = m3.toByteArray();

    out.writeInt(bytes.length);
    out.write(bytes, 0, 6);
    out.flush();
    return bytes;
  }