@SuppressWarnings("unchecked") public SenseData decode(ByteBuffer buffer) throws IOException { DataInputStream in = new DataInputStream(new ByteBufferInputStream(buffer)); int b1 = in.readUnsignedByte(); ResponseCode code = ResponseCode.valueOf((byte) (b1 & 0x7F)); // throws IOException SenseData sense = null; switch (code) { case CURRENT_FIXED: sense = new FixedSenseData(); break; case CURRENT_DESCRIPTOR: sense = new DescriptorSenseData(); break; case DEFERRED_FIXED: sense = new FixedSenseData(); break; case DEFERRED_DESCRIPTOR: sense = new DescriptorSenseData(); break; } sense.decode(new byte[] {(byte) b1}, buffer); return sense; }
public FixedSenseData( boolean current, KCQ kcq, byte[] information, byte[] commandSpecificInformation, SenseKeySpecificField senseKeySpecific) { super( ResponseCode.valueOf(current, false), kcq, information, commandSpecificInformation, senseKeySpecific); }
@Override public void decode(byte[] header, ByteBuffer input) throws IOException { assert header != null && header.length == 1 : "input header is invalid"; boolean valid = (header[0] & 0x80) != 0; this.setResponseCode(ResponseCode.valueOf((byte) (header[0] & 0x7F))); DataInputStream in = new DataInputStream(new ByteBufferInputStream(input)); // read in first segment of fixed format sense data in.readByte(); int key = in.readUnsignedByte() & 0x0F; // TODO: FILEMARK, EOM, and ILI are unsupported byte[] info = new byte[4]; in.read(info); int length = in.readUnsignedByte() - 10; // length of next segment, minus required read-in length = length < 0 ? 0 : length; // read in the next segment of the fixed format sense data byte[] cmdi = new byte[4]; in.read(cmdi); int code = in.readUnsignedByte(); int qualifier = in.readUnsignedByte(); in.readByte(); this.senseKeySpecificBuffer = new byte[3]; in.read(this.senseKeySpecificBuffer); // the rest of the additional sense bytes are ignored // (vendor specific bytes not supported) in.skip(length); KCQ kcq = KCQ.valueOf(key, code, qualifier); // throws IOException on invalid values // Set appropriate fields this.setKcq(kcq); this.setInformation(valid ? info : null); this.setCommandSpecificInformation(cmdi); // sense key specific buffer already set, will be decoded when exception is constructed. }