Example usage for java.io DataInputStream readInt

List of usage examples for java.io DataInputStream readInt

Introduction

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

Prototype

public final int readInt() throws IOException 

Source Link

Document

See the general contract of the readInt method of DataInput.

Usage

From source file:org.apache.xmlgraphics.image.codec.png.PNGChunk.java

/**
 * Returns the PNG chunk type, a four letter case sensitive ASCII type/name.
 * @param distream the input stream/*  w  w w  .java  2 s .  c om*/
 * @return a four letter case sensitive ASCII type/name
 */
public static String getChunkType(DataInputStream distream) {
    try {
        distream.mark(8);
        /* int length = */distream.readInt();
        int type = distream.readInt();
        distream.reset();

        return typeIntToString(type);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static int[] convertB64Toint(byte[] a1) {
    byte[] a = decode(a1);
    try {//from w ww .  j a  va2s  .  c  o  m
        ByteArrayInputStream is = new ByteArrayInputStream(a1);
        DataInputStream di = new DataInputStream(is);
        int[] f = new int[a.length / 4];
        for (int i = 0; i < f.length; i++)
            f[i] = di.readInt();
        return f;
    } catch (Exception s) {
        return null;
    }

}

From source file:Main.java

public static int[] readBin83PtIndex(String dir, String fileName) {
    int i = 0;//from   w ww .  j  a va 2  s. c  om
    int x = 0;
    int[] tab = new int[83];
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        x = in.readInt();
        while (true) {
            tab[i] = x;
            i++;
            x = in.readInt();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:Main.java

public static int[] readBinIntArray(String dir, String fileName, int size) {
    int x;//from   w w  w . java  2  s.c  om
    int i = 0;
    int[] tab = new int[size];
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        x = in.readInt();
        while (true) {
            tab[i] = x;
            i++;
            x = in.readInt();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:com.orange.ocara.model.export.docx.DocxWriterTest.java

/**
 * Determine whether a file is a ZIP File.
 *//* ww  w.  j a  va 2 s . c  o  m*/
private static boolean isZipFile(File file) throws IOException {
    if (file.isDirectory()) {
        return false;
    }
    if (!file.canRead()) {
        throw new IOException("Cannot read file " + file.getAbsolutePath());
    }
    if (file.length() < 4) {
        return false;
    }
    DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
    int test = in.readInt();
    in.close();
    return test == 0x504b0304;
}

From source file:org.locationtech.geomesa.bigtable.spark.BigtableInputFormatBase.java

public static BigtableExtendedScan stringToScan(String encoded) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(encoded)));
    int tableLength = dis.readInt();
    byte[] table = new byte[tableLength];
    dis.read(table, 0, tableLength);/*from w  ww . ja  v  a2  s .  c om*/
    int available = dis.available();
    byte[] rowsetbytes = new byte[available];
    dis.readFully(rowsetbytes);
    RowSet rs = RowSet.parseFrom(rowsetbytes);
    BigtableExtendedScan scan = new BigtableExtendedScan();
    rs.getRowRangesList().forEach(scan::addRange);
    scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, table);
    return scan;
}

From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java

private static StoreExtendOperation readStoreExtendOperation(DataInputStream in) throws IOException {
    long transactionId = in.readLong();
    int blockSize = in.readInt();
    int oldBlockCount = in.readInt();
    int newBlockCount = in.readInt();

    return new StoreExtendOperation(transactionId, blockSize, oldBlockCount, newBlockCount);
}

From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java

private static CommitOperation readCommitOperation(DataInputStream in) throws IOException {
    long transactionId = in.readLong();
    int operationsCount = in.readInt();

    return new CommitOperation(transactionId, operationsCount, null);
}

From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java

private static String deserializeString(DataInputStream dis) throws IOException {
    int stringLength = dis.readInt();
    byte[] bytes = new byte[stringLength];
    dis.readFully(bytes);/* w  w w  .jav a2s  .c  om*/
    return new String(bytes);
}

From source file:org.apache.hadoop.hbase.security.HBaseSaslRpcClient.java

private static void readStatus(DataInputStream inStream) throws IOException {
    int status = inStream.readInt(); // read status
    if (status != SaslStatus.SUCCESS.state) {
        throw new RemoteException(WritableUtils.readString(inStream), WritableUtils.readString(inStream));
    }/*from   w  w  w  .j  a  va2s  .  c  o  m*/
}