try
{
byte[] info = this.getInformation();
byte[] cmdi = this.getCommandSpecificInformation();
KCQ kcq = this.getKCQ();
SenseKeySpecificField field = this.getSenseKeySpecific();
if (field == null)
{
field = new NoSenseKeySpecific();
}
// returned response code is byte with max value 0x7F (7-bit).
int response = this.getResponseCode();
// We mark VALID as 0 if info is null or over max size (4-byte).
if (info != null && info.length == 4)
{
response |= 0x80;
}
else if (info.length < 4)
{
throw new RuntimeException("Returned sense information has invalid length: "
+ info.length);
}
else
{
info = new byte[4]; // Ignore invalid or null value, will write all zeros to field
}
if (cmdi == null || cmdi.length != 4)
{
cmdi = new byte[4]; // Ignore invalid command specific information lengths.
}
out.writeByte(response); // VALID and RESPONSE CODE
out.writeByte(0);
out.writeByte(kcq.key().value()); // TODO: FILEMARK, EOM, and ILI not current supported
out.write(info);
out.writeByte(10); // no "Additional sense bytes" will be written, last byte is #17
out.write(cmdi);
out.writeByte(kcq.code());
out.writeByte(kcq.qualifier());
out.writeByte(0);
out.write(field.encode());
assert bs.toByteArray().length == FIXED_SENSE_DATA_LENGTH : "Invalid encoded sense data";
}
catch (IOException e)
{