package net.alphadev.usbstorage.scsi;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 * Created by jan on 27.08.14.
 */
public class CommandStatusWrapper {
    private byte[] mSignature;
    private int mTag;
    private int mDataResidue;
    private byte mStatus;

    public CommandStatusWrapper(byte[] data) {
        if (data.length != 13) {
            throw new IllegalArgumentException("CSW always has a length of 13 bytes!");
        }

        mSignature = new byte[4];
        mSignature[0x0] = data[0x0];
        mSignature[0x1] = data[0x1];
        mSignature[0x2] = data[0x2];
        mSignature[0x3] = data[0x3];

        mTag = ByteBuffer.wrap(data, 0x4, 4).order(ByteOrder.LITTLE_ENDIAN).getInt();
        mDataResidue = mTag = ByteBuffer.wrap(data, 0x8, 4).order(ByteOrder.LITTLE_ENDIAN).getInt();
        mStatus = data[0xc];
    }

    public String getSignature() {
        return new String(mSignature);
    }

    public int getTag() {
        return mTag;
    }

    public int getDataResidue() {
        return mDataResidue;
    }

    public byte getStatus() {
        return mStatus;
    }
}

@@ -36,64 +36,8 @@
 i;%0A%0A
-import java.nio.ByteBuffer;%0Aimport java.nio.ByteOrder;%0A%0A
 /**%0A
@@ -598,188 +598,469 @@
 g = 
-ByteBuffer.wrap(data, 0x4, 4).order(ByteOrder.LITTLE_ENDIAN).getInt();%0A        mDataResidue = mTag = ByteBuffer.wrap(data, 0x8, 4).order(ByteOrder.LITTLE_ENDIAN).getInt(
+convertToInt(data, 0x4);%0A        mDataResidue = convertToInt(data, 0x8);%0A        mStatus = data%5B0xc%5D;%0A    %7D%0A%0A    private static int convertToInt(byte%5B%5D byteArray, int offset) %7B%0A        byte c1 = byteArray%5Boffset + 3%5D;%0A        byte c2 = byteArray%5Boffset + 2%5D;%0A        byte c3 = byteArray%5Boffset + 1%5D;%0A        byte c4 = byteArray%5Boffset%5D;%0A%0A        long temp =%0A                ((0xFF & c1) %3C%3C 24) %7C ((0xFF & c2) %3C%3C 16) %7C ((0xFF & c3) %3C%3C 8) %7C (0xFF & c4
 );%0A
+%0A
         
 mSta
@@ -1055,35 +1055,50 @@
         
-mStatus = data%5B0xc%5D
+return (int) (temp & 0x0FFFFFFFFL)
 ;%0A    %7D%0A

replace ByteBuffer int casting with own solution.