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:com.facebook.infrastructure.db.Column.java

private IColumn defreeze(DataInputStream dis, String name) throws IOException {
    IColumn column = null;//  ww  w. j  av  a  2 s  .c  o m
    boolean delete = dis.readBoolean();
    long ts = dis.readLong();
    int size = dis.readInt();
    byte[] value = new byte[size];
    dis.readFully(value);
    column = new Column(name, value, ts, delete);
    return column;
}

From source file:com.xpn.xwiki.plugin.zipexplorer.ZipExplorerPlugin.java

/**
 * @param filecontent the content of the file
 * @return true if the file is in zip format (.zip, .jar etc) or false otherwise
 *//*from  w  ww.  j a  v  a2 s .co m*/
protected boolean isZipFile(InputStream filecontent) {
    int standardZipHeader = 0x504b0304;
    filecontent.mark(8);
    try {
        DataInputStream datastream = new DataInputStream(filecontent);
        int fileHeader = datastream.readInt();
        return (standardZipHeader == fileHeader);
    } catch (IOException e) {
        // The file doesn't have 4 bytes, so it isn't a zip file
    } finally {
        // Reset the input stream to the beginning. This may be needed for further reading the archive.
        try {
            filecontent.reset();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return false;
}

From source file:mitm.common.security.crypto.PBEncryptedStreamParameters.java

private void fromInputStream(InputStream input) throws IOException {
    DataInputStream dis = new DataInputStream(input);

    long version = dis.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }/* ww  w  . java 2  s.  c om*/

    algorithm = dis.readUTF();

    int saltSize = dis.readInt();

    this.salt = new byte[saltSize];

    dis.readFully(salt);

    this.iterationCount = dis.readInt();
}

From source file:org.eclipse.gyrex.cloud.internal.queue.Message.java

/**
 * Creates a new instance./*from  ww w.j a v a2  s  .c o  m*/
 * 
 * @param zooKeeperQueue
 * @param messageId
 * @param record
 * @param stat
 * @throws IOException
 */
public Message(final String messageId, final ZooKeeperQueue zooKeeperQueue, final byte[] record,
        final Stat stat) throws IOException {
    this.messageId = messageId;
    this.zooKeeperQueue = zooKeeperQueue;
    queueId = zooKeeperQueue.id;
    zkNodeDataVersion = stat.getVersion();

    final DataInputStream din = new DataInputStream(new ByteArrayInputStream(record));

    // serialized format version
    final int formatVersion = din.readInt();
    if (formatVersion != 1)
        throw new IllegalArgumentException(String
                .format("invalid record data: version mismatch (expected %d, found %d)", 1, formatVersion));

    // timeout
    invisibleTimeoutTS = din.readLong();

    // body size
    final int length = din.readInt();

    // body
    body = new byte[length];
    final int read = din.read(body);
    if (read != length)
        throw new IllegalArgumentException(
                String.format("invalid record data: body size mismatch (expected %d, read %d)", length, read));
}

From source file:org.structr.core.graph.SyncCommand.java

public static Object deserialize(final DataInputStream inputStream) throws IOException {

    Object serializedObject = null;
    final byte type = inputStream.readByte();
    Class clazz = classMap.get(type);

    if (clazz != null) {

        if (clazz.isArray()) {

            // len is the length of the underlying array
            final int len = inputStream.readInt();
            final Object[] array = (Object[]) Array.newInstance(clazz.getComponentType(), len);

            for (int i = 0; i < len; i++) {

                array[i] = deserialize(inputStream);
            }//from  w w  w  .  j a  v a 2s  . co m

            // set array
            serializedObject = array;

        } else {

            serializedObject = readObject(inputStream, type);
        }

    } else if (type != 127) {

        logger.log(Level.WARNING, "Unsupported type \"{0}\" in input", type);
    }

    return serializedObject;
}

From source file:com.bigdata.dastor.db.RowMutation.java

private Map<String, ColumnFamily> defreezeTheMaps(DataInputStream dis) throws IOException {
    Map<String, ColumnFamily> map = new HashMap<String, ColumnFamily>();
    int size = dis.readInt();
    for (int i = 0; i < size; ++i) {
        String key = dis.readUTF();
        ColumnFamily cf = ColumnFamily.serializer().deserialize(dis);
        map.put(key, cf);//from   ww w . j  a  v a2  s .c  om
    }
    return map;
}

From source file:org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService.java

private byte[] readLengthDelimitedResponse(final DataInputStream dis) throws IOException {
    final int responseLength = dis.readInt();
    final byte[] responseBuffer = new byte[responseLength];
    dis.readFully(responseBuffer);//from  w  w  w .  ja  v  a2 s .c  o m
    return responseBuffer;
}

From source file:FilterFieldsMIDlet.java

public boolean matches(byte[] candidate) {
    DataInputStream student = new DataInputStream(new ByteArrayInputStream(candidate));
    int average = 0;
    try {/*from  www  .  j a va 2 s  .c om*/
        String dummy = student.readUTF();
        average = (student.readInt() + student.readInt() + student.readInt()) / 3;

    } catch (Exception e) {
    }
    if (average >= 80)
        return true;
    else
        return false;

}

From source file:com.yahoo.pulsar.testclient.LoadSimulationClient.java

private void decodeProducerOptions(final TradeConfiguration tradeConf, final DataInputStream inputStream)
        throws Exception {
    tradeConf.topic = inputStream.readUTF();
    tradeConf.size = inputStream.readInt();
    tradeConf.rate = inputStream.readDouble();
}

From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java

protected List<VEdge> readVertexEdge(VSubGraph graph, long vertexId, DataInputStream stream)
        throws IOException {
    int edgeCount = stream.readInt();
    List<VEdge> edges = new ArrayList<VEdge>(edgeCount);
    for (int i = 0; i < edgeCount; i++) {
        long edgeId = readElementId(stream);
        String edgeLabel = readElementLabel(stream);
        boolean direction = stream.readBoolean();
        boolean sharedShard = stream.readBoolean();
        VSubGraph graphTwo = null;//from   w w  w  .  jav a  2  s .  c  o  m
        if (sharedShard) {
            graphTwo = graph;
        } else {
            long graphTwoId = readElementId(stream);
            if (getGraph() != null) {
                graphTwo = getGraph().getGraphShard(graphTwoId);
            } else {
                graphTwo = new VSubGraph(graphTwoId, 1);
            }
        }
        long otherVertexId = readElementId(stream);
        if (direction) {
            VEdge edge = new VEdge(edgeId, edgeLabel, otherVertexId, graphTwo, vertexId, graph);
            edges.add(edge);
        } else {
            VEdge edge = new VEdge(edgeId, edgeLabel, vertexId, graph, otherVertexId, graphTwo);
            edges.add(edge);
        }
    }
    return edges;
}