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.teatrove.teaapps.contexts.EncodingContext.java

/**
 * Decode the given Base64 encoded value into an integer array.
 * /*w w  w.  j  av a 2  s.co m*/
 * @param input The Base64 encoded value to decode
 * 
 * @return The array of decoded integers
 * 
 * @throws IOException if an error occurs decoding the array stream
 * 
 * @see #encodeIntArray(int[])
 */
public int[] decodeIntArray(String input) throws IOException {
    int[] result = null;
    ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(input));
    DataInputStream dis = new DataInputStream(bis);
    int length = dis.readInt();
    result = new int[length];
    for (int i = 0; i < length; i++) {
        result[i] = dis.readInt();
    }
    return result;
}

From source file:com.exzogeni.dk.http.cache.DiscCacheStore.java

private long readMetaFile(@NonNull File metaFile, @NonNull Map<String, List<String>> headers)
        throws IOException {
    final AtomicFile af = new AtomicFile(metaFile);
    final FileInputStream fis = af.openRead();
    final DataInputStream dat = new DataInputStream(new BufferPoolInputStream(fis));
    try {/*from   ww w .j  a  va 2  s .c  om*/
        final long expireTime = dat.readLong();
        int headersCount = dat.readInt();
        while (headersCount-- > 0) {
            final String name = dat.readUTF();
            int valuesCount = dat.readInt();
            final List<String> values = new ArrayList<>(valuesCount);
            while (valuesCount-- > 0) {
                values.add(dat.readUTF());
            }
            headers.put(name, values);
        }
        return expireTime;
    } finally {
        IOUtils.closeQuietly(dat);
    }
}

From source file:RMSGameScores.java

/**
 * A helper method for the printScores methods.
 *//*w w  w. ja  v a2 s.  com*/
private void printScoresHelper(RecordEnumeration re) {

    try {
        while (re.hasNextElement()) {
            int id = re.nextRecordId();
            ByteArrayInputStream bais = new ByteArrayInputStream(recordStore.getRecord(id));
            DataInputStream inputStream = new DataInputStream(bais);
            try {
                int score = inputStream.readInt();
                String playerName = inputStream.readUTF();
                System.out.println(playerName + " = " + score);
            } catch (EOFException eofe) {
                System.out.println(eofe);
                eofe.printStackTrace();
            }
        }
    } catch (RecordStoreException rse) {
        System.out.println(rse);
        rse.printStackTrace();
    } catch (IOException ioe) {
        System.out.println(ioe);
        ioe.printStackTrace();
    }
}

From source file:org.getspout.spout.packet.PacketCacheFile.java

public void readData(DataInputStream input) throws IOException {
    this.fileName = PacketUtil.readString(input);
    this.plugin = PacketUtil.readString(input);
    compressed = input.readBoolean();//from  w  w w .ja va  2  s.co m
    int size = input.readInt();
    this.fileData = new byte[size];
    input.readFully(this.fileData);
}

From source file:RetrieveAllMIDlet.java

public boolean matches(byte[] candidate) {
    DataInputStream student = new DataInputStream(new ByteArrayInputStream(candidate));
    int average = 0;
    try {/*from  w w w.j  a v  a  2s . c om*/
        average = (student.readInt() + student.readInt() + student.readInt()) / 3;
    } catch (Exception e) {
    }
    if (average >= 80)
        return true;
    else
        return false;

}

From source file:org.outerrim.snippad.ui.swt.dnd.WikiTransfer.java

/**
 * Converts a byte array into a WikiWord array.
 *
 * @param bytes/* w  w  w  .  j  a  va2s  .  c o m*/
 *            byte array to transform
 * @return WikiWord array
 */
private WikiWord[] fromByteArray(final byte[] bytes) {
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));

    try {
        // read number of words
        int n = in.readInt();

        // read words
        WikiWord[] words = new WikiWord[n];
        for (int i = 0; i < n; ++i) {
            WikiWord word = readWikiWord(null, in);
            if (word == null) {
                return null;
            }
            words[i] = word;
        }
        return words;
    } catch (IOException e) {
        LOG.debug("fromByteArray()", e);
        return null;
    }
}

From source file:org.apache.cassandra.db.ReadCommand.java

public ReadCommand deserialize(DataInputStream dis) throws IOException {
    String table = dis.readUTF();
    String key = dis.readUTF();/*from  w ww  .  j  a v  a  2s.c om*/
    String columnFamily_column = dis.readUTF();
    int start = dis.readInt();
    int count = dis.readInt();
    long sinceTimestamp = dis.readLong();
    boolean isDigest = dis.readBoolean();

    int size = dis.readInt();
    List<String> columns = new ArrayList<String>();
    for (int i = 0; i < size; ++i) {
        byte[] bytes = new byte[dis.readInt()];
        dis.readFully(bytes);
        columns.add(new String(bytes));
    }
    ReadCommand rm = null;
    if (columns.size() > 0) {
        rm = new ReadCommand(table, key, columnFamily_column, columns);
    } else if (sinceTimestamp > 0) {
        rm = new ReadCommand(table, key, columnFamily_column, sinceTimestamp);
    } else {
        rm = new ReadCommand(table, key, columnFamily_column, start, count);
    }
    rm.setDigestQuery(isDigest);
    return rm;
}

From source file:RMSGameScores.java

public boolean matches(byte[] candidate) throws IllegalArgumentException {
    // If no filter set, nothing can match it.
    if (this.playerNameFilter == null) {
        return false;
    }//from  ww  w. j a  va2  s. c  om

    ByteArrayInputStream bais = new ByteArrayInputStream(candidate);
    DataInputStream inputStream = new DataInputStream(bais);
    String name = null;

    try {
        int score = inputStream.readInt();
        name = inputStream.readUTF();
    } catch (EOFException eofe) {
        System.out.println(eofe);
        eofe.printStackTrace();
    } catch (IOException eofe) {
        System.out.println(eofe);
        eofe.printStackTrace();
    }
    return (this.playerNameFilter.equals(name));
}

From source file:org.xenei.compressedgraph.SerializableNode.java

private String read(DataInputStream is) throws IOException {
    int n = is.readInt();
    if (n == -1) {
        return null;
    }/*ww  w  .  j a  v  a2  s.co m*/
    byte[] b = new byte[n];
    if (n > 0) {
        is.read(b);
    }
    return decodeString(b);
}

From source file:com.igormaznitsa.jhexed.renders.svg.SVGImage.java

public SVGImage(final InputStream in, final boolean packed) throws IOException {
    final DataInputStream din = in instanceof DataInputStream ? (DataInputStream) in : new DataInputStream(in);
    if (packed) {
        final byte[] packedImageData = new byte[din.readInt()];
        IOUtils.readFully(din, packedImageData);
        this.originalNonParsedImageData = Utils.unpackArray(packedImageData);
    } else {//  w ww  .  ja  v a  2 s . com
        this.originalNonParsedImageData = readFullInputStream(din);
    }
    this.quality = din.readBoolean();

    this.svgGraphicsNode = loadDiagramFromStream(new ByteArrayInputStream(this.originalNonParsedImageData),
            this.documentSize);
}