@Test public void testAcceptsEmptyPayload() throws Exception { byte[] header = new byte[] {1, 2, 0, 0}; ByteArrayInputStream in = new ByteArrayInputStream(header); RecordReader reader = new RecordReaderImpl(in); Record record = reader.readRecord(); assertEquals(1, record.getProtocolVersion()); assertEquals(2, record.getRecordType()); assertArrayEquals(new byte[0], record.getPayload()); }
@Override public Record readRecord() throws IOException { in.readFully(header); byte protocolVersion = header[0]; byte recordType = header[1]; int payloadLength = ByteUtils.readUint16(header, 2); if (payloadLength < 0 || payloadLength > MAX_RECORD_PAYLOAD_BYTES) throw new FormatException(); byte[] payload = new byte[payloadLength]; in.readFully(payload); return new Record(protocolVersion, recordType, payload); }
RecordReaderImpl implements RecordReader { @Override public Record readRecord() throws IOException { in.readFully(header); byte protocolVersion = header[0]; byte recordType = header[1]; int payloadLength = ByteUtils.readUint16(header, 2); if (payloadLength < 0 || payloadLength > MAX_RECORD_PAYLOAD_BYTES) throw new FormatException(); byte[] payload = new byte[payloadLength]; in.readFully(payload); return new Record(protocolVersion, recordType, payload); } }
RecordReaderImpl implements RecordReader { @Override public Record readRecord() throws IOException { in.readFully(header); byte protocolVersion = header[0]; byte recordType = header[1]; int payloadLength = ByteUtils.readUint16(header, 2); if (payloadLength < 0 || payloadLength > MAX_RECORD_PAYLOAD_BYTES) throw new FormatException(); byte[] payload = new byte[payloadLength]; in.readFully(payload); return new Record(protocolVersion, recordType, payload); } RecordReaderImpl(InputStream in); }
RecordReaderImpl implements RecordReader { @Override public Record readRecord() throws IOException { in.readFully(header); byte protocolVersion = header[0]; byte recordType = header[1]; int payloadLength = ByteUtils.readUint16(header, 2); if (payloadLength < 0 || payloadLength > MAX_RECORD_PAYLOAD_BYTES) throw new FormatException(); byte[] payload = new byte[payloadLength]; in.readFully(payload); return new Record(protocolVersion, recordType, payload); } RecordReaderImpl(InputStream in); @Override Record readRecord(); @Override void close(); }
RecordReaderImpl implements RecordReader { @Override public Record readRecord() throws IOException { in.readFully(header); byte protocolVersion = header[0]; byte recordType = header[1]; int payloadLength = ByteUtils.readUint16(header, 2); if (payloadLength < 0 || payloadLength > MAX_RECORD_PAYLOAD_BYTES) throw new FormatException(); byte[] payload = new byte[payloadLength]; in.readFully(payload); return new Record(protocolVersion, recordType, payload); } RecordReaderImpl(InputStream in); @Override Record readRecord(); @Override void close();  }