@Test(groups = "checkintest", expectedExceptions = InvalidCommandLengthException.class) public void testInvalidPDUHeaderWithCommandLengthEigth() throws Exception { DefaultPDUReader defaultPDUReader = new DefaultPDUReader(); DataInputStream in = new DataInputStream( new ByteArrayInputStream( new byte[]{ 0x00, 0x00, 0x00, 0x08, 0x01, 0x02, 0x03, 0x04 })); defaultPDUReader.readPDUHeader(in); }
@Override public Command readPDUHeader(DataInputStream in) throws InvalidCommandLengthException, IOException { Command header = new Command(); header.setCommandLength(in.readInt()); if (header.getCommandLength() < PDU_HEADER_LENGTH) { byte[] dump = new byte[header.getCommandLength()]; if (header.getCommandLength() >= 4) { in.read(dump, 4, header.getCommandLength() - 4); } throw new InvalidCommandLengthException("Command length " + header.getCommandLength() + " is too short"); } header.setCommandId(in.readInt()); header.setCommandStatus(in.readInt()); header.setSequenceNumber(in.readInt()); return header; }
DefaultPDUReader implements PDUReader { @Override public Command readPDUHeader(DataInputStream in) throws InvalidCommandLengthException, IOException { Command header = new Command(); header.setCommandLength(in.readInt()); if (header.getCommandLength() < PDU_HEADER_LENGTH) { byte[] dump = new byte[header.getCommandLength()]; if (header.getCommandLength() >= 4) { in.read(dump, 4, header.getCommandLength() - 4); } throw new InvalidCommandLengthException("Command length " + header.getCommandLength() + " is too short"); } header.setCommandId(in.readInt()); header.setCommandStatus(in.readInt()); header.setSequenceNumber(in.readInt()); return header; } }
DefaultPDUReader implements PDUReader { @Override public Command readPDUHeader(DataInputStream in) throws InvalidCommandLengthException, IOException { Command header = new Command(); header.setCommandLength(in.readInt()); if (header.getCommandLength() < PDU_HEADER_LENGTH) { byte[] dump = new byte[header.getCommandLength()]; if (header.getCommandLength() >= 4) { in.read(dump, 4, header.getCommandLength() - 4); } throw new InvalidCommandLengthException("Command length " + header.getCommandLength() + " is too short"); } header.setCommandId(in.readInt()); header.setCommandStatus(in.readInt()); header.setSequenceNumber(in.readInt()); return header; }  }
DefaultPDUReader implements PDUReader { @Override public Command readPDUHeader(DataInputStream in) throws InvalidCommandLengthException, IOException { Command header = new Command(); header.setCommandLength(in.readInt()); if (header.getCommandLength() < PDU_HEADER_LENGTH) { byte[] dump = new byte[header.getCommandLength()]; if (header.getCommandLength() >= 4) { in.read(dump, 4, header.getCommandLength() - 4); } throw new InvalidCommandLengthException("Command length " + header.getCommandLength() + " is too short"); } header.setCommandId(in.readInt()); header.setCommandStatus(in.readInt()); header.setSequenceNumber(in.readInt()); return header; }  @Override Command readPDUHeader(DataInputStream in); @Override byte[] readPDU(DataInputStream in, Command pduHeader); @Override byte[] readPDU(DataInputStream in, int commandLength, int commandId,
            int commandStatus, int sequenceNumber); }
DefaultPDUReader implements PDUReader { @Override public Command readPDUHeader(DataInputStream in) throws InvalidCommandLengthException, IOException { Command header = new Command(); header.setCommandLength(in.readInt()); if (header.getCommandLength() < PDU_HEADER_LENGTH) { byte[] dump = new byte[header.getCommandLength()]; if (header.getCommandLength() >= 4) { in.read(dump, 4, header.getCommandLength() - 4); } throw new InvalidCommandLengthException("Command length " + header.getCommandLength() + " is too short"); } header.setCommandId(in.readInt()); header.setCommandStatus(in.readInt()); header.setSequenceNumber(in.readInt()); return header; }  @Override Command readPDUHeader(DataInputStream in); @Override byte[] readPDU(DataInputStream in, Command pduHeader); @Override byte[] readPDU(DataInputStream in, int commandLength, int commandId,
            int commandStatus, int sequenceNumber);  }