Esempio n. 1
0
 @Override
 public List<Object> nextRecord() throws IOException {
   long start = channel.position();
   try {
     if (in.available() >= 4) {
       int n = in.readInt();
       byte[] buf = new byte[n];
       in.readFully(buf);
       MessageQueue.Message m = MessageQueue.Message.parseFrom(buf);
       return parser.parse(m.getPayload());
     } else {
       return null;
     }
   } catch (EOFException e) {
     channel.position(start);
     return null;
   }
 }
Esempio n. 2
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;
  }