@Test(expected = FormatException.class) public void testFormatExceptionIfPayloadLengthIsTooLarge() throws Exception { byte[] header = new byte[] {1, 2, 0, 0}; ByteUtils.writeUint16(MAX_RECORD_PAYLOAD_BYTES + 1, header, 2); ByteArrayInputStream in = new ByteArrayInputStream(header); 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();  }