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:tachyon.io.Utils.java

public static List<Integer> readIntegerList(DataInputStream is) throws IOException {
    int size = is.readInt();
    if (size == -1) {
        return null;
    }//  w  w  w. j  ava  2  s . c o m
    List<Integer> ret = new ArrayList<Integer>(size);
    for (int k = 0; k < size; k++) {
        ret.add(is.readInt());
    }
    return ret;
}

From source file:tachyon.io.Utils.java

public static ByteBuffer readByteBuffer(DataInputStream is) throws IOException {
    int len = is.readInt();
    if (len == -1) {
        return null;
    }//  w w  w . j  a  va 2 s .c o m

    byte[] arr = new byte[len];
    for (int k = 0; k < len; k++) {
        arr[k] = is.readByte();
    }

    return ByteBuffer.wrap(arr);
}

From source file:tachyon.io.Utils.java

public static List<ByteBuffer> readByteBufferList(DataInputStream is) throws IOException {
    int size = is.readInt();
    if (size == -1) {
        return null;
    }//from  w w w . j  av  a 2  s.c  o  m

    List<ByteBuffer> ret = new ArrayList<ByteBuffer>(size);
    for (int k = 0; k < size; k++) {
        ret.add(readByteBuffer(is));
    }
    return ret;
}

From source file:tachyon.io.Utils.java

public static List<String> readStringList(DataInputStream is) throws IOException {
    int size = is.readInt();

    if (size == -1) {
        return null;
    }// w w  w  .  j a  va2  s.c  om

    List<String> ret = new ArrayList<String>(size);
    for (int k = 0; k < size; k++) {
        ret.add(readString(is));
    }
    return ret;
}

From source file:tachyon.io.Utils.java

public static String readString(DataInputStream is) throws IOException {
    int len = is.readInt();

    if (len == -1) {
        return null;
    } else if (len == 0) {
        return "";
    }//from  w  w  w  . j  a  va2  s  .c o  m

    char[] chars = new char[len];
    for (int k = 0; k < len; k++) {
        chars[k] = is.readChar();
    }
    return new String(chars);

}

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

/**
 * Reads the next chunk from the input stream.
 * @param distream the input stream//from   w w w  . ja v a  2 s .c  om
 * @return the chunk
 */
public static PNGChunk readChunk(DataInputStream distream) {
    try {
        int length = distream.readInt();
        int type = distream.readInt();
        byte[] data = new byte[length];
        distream.readFully(data);
        int crc = distream.readInt();

        return new PNGChunk(length, type, data, crc);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

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

/**
 * Skips the next chunk from the input stream.
 * @param distream the input stream/*from w  w  w  . ja  va  2s  . co m*/
 * @return true if skipping successful, false otherwise
 */
public static boolean skipChunk(DataInputStream distream) {
    try {
        int length = distream.readInt();
        int type = distream.readInt();
        // is this really faster than reading?
        int skipped = distream.skipBytes(length);
        int crc = distream.readInt();
        if (skipped != length) {
            log.warn("Incorrect number of bytes skipped.");
            return false;
        }
        return true;
    } catch (Exception e) {
        log.warn(e.getMessage());
        return false;
    }
}

From source file:com.opensoc.json.serialization.JSONDecoderHelper.java

@SuppressWarnings("unchecked")
public static JSONArray getArray(DataInputStream data) throws IOException {
    // TODO Auto-generated method stub
    JSONArray output = new JSONArray();
    int size = data.readInt();

    for (int i = 0; i < size; i++) {
        Object value = getObject(data);
        output.add(value);//from   w  ww .ja  v a 2s  .  c om
    }

    return output;
}

From source file:com.opensoc.json.serialization.JSONDecoderHelper.java

@SuppressWarnings("unchecked")
public static JSONObject getJSON(DataInputStream data) throws IOException {
    // TODO Auto-generated method stub
    JSONObject output = new JSONObject();
    int size = data.readInt();

    for (int i = 0; i < size; i++) {
        String key = (String) getObject(data);
        Object value = getObject(data);
        output.put(key, value);/*from   w  w  w. j a  v  a 2s  .c  o m*/
    }

    return output;
}

From source file:org.gitools.matrix.format.CmatrixMatrixFormat.java

/**
 * Read a byte array that starts with an integer that contains the buffer length to read.
 *
 * @param in the input stream//from   www .ja  v  a2 s .  c om
 * @return the byte array
 * @throws IOException
 */
public static byte[] readBuffer(DataInputStream in) throws IOException {
    int length = in.readInt();
    return IOUtils.toByteArray(in, length);
}