@Test(expected = EOFException.class) public void testEofExceptionIfPayloadLengthIsMissing() throws Exception { ByteArrayInputStream in = new ByteArrayInputStream(new byte[2]); RecordReader reader = new RecordReaderImpl(in); reader.readRecord(); }
@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();  }