Example usage for java.io DataInputStream readFully

List of usage examples for java.io DataInputStream readFully

Introduction

In this page you can find the example usage for java.io DataInputStream readFully.

Prototype

public final void readFully(byte b[]) throws IOException 

Source Link

Document

See the general contract of the readFully method of DataInput .

Usage

From source file:VASSAL.tools.imports.adc2.MapBoard.java

/**
 * Read information on hex numbering.//from w ww  .  j a v  a  2  s  .c om
 */
protected void readMapSheetBlock(DataInputStream in) throws IOException {
    ADC2Utils.readBlockHeader(in, "Map Sheet");

    int nMapSheets = ADC2Utils.readBase250Word(in);
    for (int i = 0; i < nMapSheets; ++i) {
        int x1 = ADC2Utils.readBase250Word(in);
        int y1 = ADC2Utils.readBase250Word(in);
        int x2 = ADC2Utils.readBase250Word(in);
        int y2 = ADC2Utils.readBase250Word(in);
        Rectangle r = new Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
        // must be exactly 9 bytes or 10 if there's a terminating null at the end
        String name = readNullTerminatedString(in, 10);
        if (name.length() < 9)
            in.readFully(new byte[9 - name.length()]);
        int style = in.readUnsignedByte();
        in.readFully(new byte[2]);
        int nColChars = in.readUnsignedByte();
        int nRowChars = in.readUnsignedByte();
        if (i < nMapSheets - 1) // the last one is always ignored.
            mapSheets.add(new MapSheet(name, r, style, nColChars, nRowChars));
    }
}

From source file:org.opensc.pkcs15.token.impl.CardOSToken.java

@Override
public TokenFile select(int path) throws IOException {

    if (this.currentFile == null)
        throw new IOException("No current DF selected.");

    // SELECT FILE, P1=0x00, P2=0x00, ID -> select EF or DF
    CommandAPDU cmd = new CommandAPDU(0x00, 0xA4, 0x00, 0x00, PathHelper.idToPath(path), DEFAULT_LE);

    try {//  w  ww .  jav  a 2  s.co m
        ResponseAPDU resp = this.channel.transmit(cmd);

        DataInputStream dis = getSelectFileData(resp);

        long bodySize = -1;
        long fileSize = -1;
        int acRead = TokenFileAcl.AC_ALWAYS;
        int acUpdate = TokenFileAcl.AC_ALWAYS;
        int acAppend = TokenFileAcl.AC_ALWAYS;
        int acDeactivate = TokenFileAcl.AC_ALWAYS;
        int acActivate = TokenFileAcl.AC_ALWAYS;
        int acDelete = TokenFileAcl.AC_ALWAYS;
        int acAdmin = TokenFileAcl.AC_ALWAYS;
        int acIncrease = TokenFileAcl.AC_ALWAYS;
        int acDecrease = TokenFileAcl.AC_ALWAYS;

        int tag;

        while ((tag = dis.read()) >= 0) {
            int n = dis.read();
            if (n < 0)
                break;

            switch (tag) {
            case 0x80:
                if (n != 2)
                    throw new IOException("Invalid length [" + n + "] of FCI tag 0x80.");
                fileSize = dis.readUnsignedShort();
                break;

            case 0x83:
                if (n != 2)
                    throw new IOException("Invalid length [" + n + "] of FCI tag 0x83.");
                int tpath = dis.readUnsignedShort();
                if (tpath != path)
                    throw new IOException("File ID [" + PathHelper.formatID(tpath)
                            + "] reported by SELECT FILE differs from requested ID ["
                            + PathHelper.formatID(path) + "].");
                break;

            case 0x81:
                if (n != 2)
                    throw new IOException("Invalid length [" + n + "] of FCI tag 0x81.");
                bodySize = dis.readUnsignedShort();
                break;

            case 0x86:
                if (n >= 1)
                    acRead = dis.read();
                if (n >= 2)
                    acUpdate = dis.read();
                if (n >= 3)
                    acAppend = dis.read();
                if (n >= 4)
                    acDeactivate = dis.read();
                if (n >= 5)
                    acActivate = dis.read();
                if (n >= 6)
                    acDelete = dis.read();
                if (n >= 7)
                    acAdmin = dis.read();
                if (n >= 8)
                    acIncrease = dis.read();
                if (n >= 9)
                    acDecrease = dis.read();

                if (n != 9 && n != 8)
                    log.warn("Invalid length [" + n + "] of FCI tag 0x86 for EF.");

                if (n > 9)
                    dis.skipBytes(n - 9);
                break;

            default:
                byte[] tmp = new byte[n];
                dis.readFully(tmp);
                log.warn("skipping FCI tag [0x" + Integer.toHexString(tag) + "], data [" + Util.asHex(tmp)
                        + "].");
            }
        }

        if (fileSize >= 0)
            this.currentFile = new EF(new TokenPath(this.currentFile.getPath(), path), fileSize, acRead,
                    acUpdate, acAppend, acDeactivate, acActivate, acDelete, acAdmin, acIncrease, acDecrease);
        else if (bodySize >= 0)
            this.currentFile = new DF(new TokenPath(this.currentFile.getPath(), path), bodySize, acRead,
                    acUpdate, acAppend, acDeactivate, acActivate, acDelete, acAdmin, acIncrease);
        else
            throw new IOException("No 0x80 or 0x81 tag specified in order to distinguish between DF an EF.");

        return this.currentFile;

    } catch (CardException e) {
        throw new PKCS15Exception("Error sending SELECT FILE", e);
    }
}