Code example for ByteArrayInputStream

Methods: read

0
        else 
            throw new Exception("Unknown file type: " + Integer.toHexString(fileType));
    } 
 
    private DesfireFileSettings (ByteArrayInputStream stream) {
        fileType    = (byte) stream.read();
        commSetting = (byte) stream.read();
 
        accessRights = new byte[2];
        stream.read(accessRights, 0, accessRights.length);
    } 
 
    private DesfireFileSettings (byte fileType, byte commSetting, byte[] accessRights) {
        this.fileType     = fileType;
        this.commSetting  = commSetting;
        this.accessRights = accessRights;
    } 
 
    public String getFileTypeName () {
        switch (fileType) {
            case STANDARD_DATA_FILE:
                return "Standard"; 
            case BACKUP_DATA_FILE:
                return "Backup"; 
            case VALUE_FILE:
                return "Value"; 
            case LINEAR_RECORD_FILE:
                return "Linear Record"; 
            case CYCLIC_RECORD_FILE:
                return "Cyclic Record"; 
            default: 
                return "Unknown"; 
        } 
    } 
 
    public static final Parcelable.Creator<DesfireFileSettings> CREATOR = new Parcelable.Creator<DesfireFileSettings>() {
        public DesfireFileSettings createFromParcel(Parcel source) { 
            byte fileType       = source.readByte(); 
            byte commSetting    = source.readByte(); 
            byte[] accessRights = new byte[source.readInt()]; 
            source.readByteArray(accessRights); 
 
            if (fileType == STANDARD_DATA_FILE || fileType == BACKUP_DATA_FILE) { 
                int fileSize = source.readInt(); 
                return new StandardDesfireFileSettings(fileType, commSetting, accessRights, fileSize); 
            } else if (fileType == LINEAR_RECORD_FILE || fileType == CYCLIC_RECORD_FILE) { 
                int recordSize = source.readInt(); 
                int maxRecords = source.readInt(); 
                int curRecords = source.readInt(); 
                return new RecordDesfireFileSettings(fileType, commSetting, accessRights, recordSize, maxRecords, curRecords); 
            } else { 
                return new UnsupportedDesfireFileSettings(fileType); 
            } 
        } 
 
        public DesfireFileSettings[] newArray(int size) { 
            return new DesfireFileSettings[size]; 
        } 
    }; 
 
    public void writeToParcel (Parcel parcel, int flags) {
        parcel.writeByte(fileType);
        parcel.writeByte(commSetting);
        parcel.writeInt(accessRights.length);
        parcel.writeByteArray(accessRights);
    } 
 
    public int describeContents () { 
        return 0; 
    } 
 
    public static class StandardDesfireFileSettings extends DesfireFileSettings { 
        public final int fileSize;
 
        private StandardDesfireFileSettings (ByteArrayInputStream stream) {
            super(stream);
            byte[] buf = new byte[3];
            stream.read(buf, 0, buf.length);
            ArrayUtils.reverse(buf);
            fileSize = Utils.byteArrayToInt(buf);
        } 
 
        StandardDesfireFileSettings (byte fileType, byte commSetting, byte[] accessRights, int fileSize) {