Example usage for java.io DataOutputStream writeInt

List of usage examples for java.io DataOutputStream writeInt

Introduction

In this page you can find the example usage for java.io DataOutputStream writeInt.

Prototype

public final void writeInt(int v) throws IOException 

Source Link

Document

Writes an int to the underlying output stream as four bytes, high byte first.

Usage

From source file:ja.lingo.engine.searchindex.NodeSerializer.java

private void serializeNodeHeader(DataOutputStream dos, int size, int childrenCount, char key, int value)
        throws IOException {
    dos.writeInt(size);
    dos.writeInt(childrenCount);/*ww  w  .  ja  va  2s. co m*/
    dos.writeInt(key);
    dos.writeInt(value);
}

From source file:com.ryan.ryanreader.cache.PersistentCookieStore.java

public synchronized byte[] toByteArray() {

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final DataOutputStream dos = new DataOutputStream(baos);

    try {//from w ww . j a  v a2 s.  c  o  m

        dos.writeInt(cookies.size());

        for (final Cookie cookie : cookies) {

            dos.writeUTF(cookie.getName());
            dos.writeUTF(cookie.getValue());
            dos.writeUTF(cookie.getDomain());
            dos.writeUTF(cookie.getPath());
            dos.writeBoolean(cookie.isSecure());
        }

        dos.flush();
        dos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return baos.toByteArray();
}

From source file:org.hyperic.hq.agent.AgentStartupCallback.java

private void writeStartupState(int state) {
    if (_startupSock == null) {
        _log.debug("Agent startup callback is disabled");
        return;/*from   w  ww.  j a  v a  2  s.c  o m*/
    }

    try {
        DataOutputStream dOs = new DataOutputStream(_startupSock.getOutputStream());
        dOs.writeInt(state);
        dOs.flush();
    } catch (IOException exc) {
        _log.error("Error writing startup state to startup port: " + exc.getMessage());
    } finally {
        try {
            _startupSock.close();
        } catch (IOException iexc) {
        }
    }
}

From source file:mitm.common.security.password.PBEncryptionParameters.java

/**
 * Returns the encoded form of PBEncryptionParameters.
 *//*from   w w w .j  a v  a  2 s  .c o m*/
public byte[] getEncoded() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    DataOutputStream out = new DataOutputStream(bos);

    out.writeLong(serialVersionUID);

    out.writeInt(salt.length);
    out.write(salt);

    out.writeInt(iterationCount);

    out.writeInt(encryptedData.length);
    out.write(encryptedData);

    return bos.toByteArray();
}

From source file:com.amalto.workbench.models.TreeObjectTransfer.java

public void javaToNative(Object object, TransferData transferData) {
    if (!checkType(object) || !isSupportedType(transferData)) {
        DND.error(DND.ERROR_INVALID_DATA);
    }/*from w  w w  .ja  va 2s  .  c  o m*/

    treeObjs = (TreeObject[]) object;
    ByteArrayOutputStream byteS = new ByteArrayOutputStream();
    DataOutputStream writeOut = new DataOutputStream(byteS);

    try {
        for (TreeObject treeData : treeObjs) {
            writeOut.writeInt(treeData.getType());
        }
        byte[] buffer = byteS.toByteArray();
        super.javaToNative(buffer, transferData);
        writeOut.close();
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

}

From source file:org.apache.hadoop.hive.accumulo.TestLazyAccumuloMap.java

protected byte[] toBytes(int i) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    out.writeInt(i);
    out.close();//from   w w w .  j  a va2 s.  co  m
    return baos.toByteArray();
}

From source file:org.spoutcraft.client.packet.PacketEntityInformation.java

public void writeData(DataOutputStream output) throws IOException {
    if (data != null) {
        output.writeInt(data.length);
        output.write(data);/*from w  w  w.  jav a  2s  . co m*/
    } else {
        output.writeInt(0);
    }
    output.writeBoolean(compressed);
}

From source file:ml.shifu.shifu.util.IndependentTreeModelUtils.java

public boolean convertBinaryToZipSpec(File treeModelFile, File outputZipFile) {
    FileInputStream treeModelInputStream = null;
    ZipOutputStream zipOutputStream = null;

    try {//from  ww w  .ja  v  a  2 s .  com
        treeModelInputStream = new FileInputStream(treeModelFile);
        IndependentTreeModel treeModel = IndependentTreeModel.loadFromStream(treeModelInputStream);
        List<List<TreeNode>> trees = treeModel.getTrees();
        treeModel.setTrees(null);
        if (CollectionUtils.isEmpty(trees)) {
            logger.error("No trees found in the tree model.");
            return false;
        }

        zipOutputStream = new ZipOutputStream(new FileOutputStream(outputZipFile));

        ZipEntry modelEntry = new ZipEntry(MODEL_CONF);
        zipOutputStream.putNextEntry(modelEntry);
        ByteArrayOutputStream byos = new ByteArrayOutputStream();
        JSONUtils.writeValue(new OutputStreamWriter(byos), treeModel);
        zipOutputStream.write(byos.toByteArray());
        IOUtils.closeQuietly(byos);

        ZipEntry treesEntry = new ZipEntry(MODEL_TREES);
        zipOutputStream.putNextEntry(treesEntry);
        DataOutputStream dataOutputStream = new DataOutputStream(zipOutputStream);
        dataOutputStream.writeInt(trees.size());
        for (List<TreeNode> forest : trees) {
            dataOutputStream.writeInt(forest.size());
            for (TreeNode treeNode : forest) {
                treeNode.write(dataOutputStream);
            }
        }
        IOUtils.closeQuietly(dataOutputStream);
    } catch (IOException e) {
        logger.error("Error occurred when convert the tree model to zip format.", e);
        return false;
    } finally {
        IOUtils.closeQuietly(zipOutputStream);
        IOUtils.closeQuietly(treeModelInputStream);
    }

    return true;
}

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

/**
 * Returns the encoded form of PBEncryptionParameters.
 *///from   w w  w .ja  v  a 2 s  .  c  o m
public byte[] getEncoded() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    DataOutputStream out = new DataOutputStream(bos);

    out.writeLong(serialVersionUID);

    out.writeUTF(algorithm);
    out.writeInt(salt.length);
    out.write(salt);

    out.writeInt(iterationCount);

    return bos.toByteArray();
}

From source file:net.sheehantech.cherry.ProtocolTest.java

private byte[] expectedEnhanced(byte command, int identifier, int expiryTime, byte[] deviceToken,
        byte[] payload) {
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    DataOutputStream dataStream = new DataOutputStream(byteStream);
    try {// w  ww.  j  a  v  a2s.  c  o m
        dataStream.writeByte(command);
        dataStream.writeInt(identifier);
        dataStream.writeInt(expiryTime);
        dataStream.writeShort(deviceToken.length);
        dataStream.write(deviceToken);
        dataStream.writeShort(payload.length);
        dataStream.write(payload);
        return byteStream.toByteArray();
    } catch (final IOException e) {
        throw new AssertionError();
    }
}