Example usage for java.io DataOutputStream writeLong

List of usage examples for java.io DataOutputStream writeLong

Introduction

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

Prototype

public final void writeLong(long v) throws IOException 

Source Link

Document

Writes a long to the underlying output stream as eight bytes, high byte first.

Usage

From source file:net.sf.keystore_explorer.crypto.x509.X509ExtensionSet.java

/**
 * Save X.509 extension set./*from   ww  w.  j  a v  a2 s.c  o m*/
 *
 * @param os
 *            Stream to save to
 * @throws IOException
 *             If an I/O problem occurred
 */
public void save(OutputStream os) throws IOException {
    DataOutputStream dos = null;

    try {
        dos = new DataOutputStream(os);

        dos.writeLong(FILE_MAGIC_NUMBER);
        dos.writeInt(FILE_VERSION);

        saveExtensions(criticalExtensions, dos);
        saveExtensions(nonCriticalExtensions, dos);
    } finally {
        IOUtils.closeQuietly(dos);
    }
}

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

protected void writeElementId(DataOutputStream stream, VElement element) throws IOException {
    stream.writeLong(element.getId());
}

From source file:org.hydracache.server.data.versioning.IncrementVersionFactory.java

@Override
public void writeObject(final Version version, final DataOutputStream dataOut) throws IOException {
    Validate.isTrue(version instanceof Increment, "version must be non null and an instance of Increment");

    Validate.notNull(dataOut, "dataOut can not be null");

    final Increment increment = (Increment) version;
    getIdentityMarshaller().writeObject(increment.getNodeId(), dataOut);
    dataOut.writeLong(increment.getValue());
}

From source file:com.serenegiant.media.TLMediaEncoder.java

/**
 * write frame header/*from w w w. jav  a2 s.c  o m*/
 * @param presentation_time_us
 * @param size
 * @throws IOException
 */
/*package*/static void writeHeader(final DataOutputStream out, final int sequence, final int frame_number,
        final long presentation_time_us, final int size, final int flag) throws IOException {

    out.writeInt(sequence);
    out.writeInt(frame_number);
    out.writeLong(presentation_time_us);
    out.writeInt(size);
    out.writeInt(flag);
    //
    out.write(RESERVED, 0, 40);
}

From source file:com.quigley.zabbixj.agent.active.ActiveThread.java

private byte[] getRequest(JSONObject jsonObject) throws Exception {
    byte[] requestBytes = jsonObject.toString().getBytes();

    String header = "ZBXD\1";
    byte[] headerBytes = header.getBytes();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    dos.writeLong(requestBytes.length);
    dos.flush();/*from w ww  .j ava  2  s  .  c o  m*/
    dos.close();
    bos.close();
    byte[] requestLengthBytes = bos.toByteArray();

    byte[] allBytes = new byte[headerBytes.length + requestLengthBytes.length + requestBytes.length];

    int index = 0;
    for (int i = 0; i < headerBytes.length; i++) {
        allBytes[index++] = headerBytes[i];
    }
    for (int i = 0; i < requestLengthBytes.length; i++) {
        allBytes[index++] = requestLengthBytes[7 - i]; // Reverse the byte order.
    }
    for (int i = 0; i < requestBytes.length; i++) {
        allBytes[index++] = requestBytes[i];
    }

    return allBytes;
}

From source file:edu.umn.cs.spatialHadoop.nasa.StockQuadTree.java

/**
 * Constructs an aggregate quad tree out of a two-dimensional array of values.
 * /*ww w. j  a  v  a2s  .co m*/
 * @param values
 * @param out
 *          - the output stream to write the constructed quad tree to
 * @throws IOException
 */
public static void build(NASADataset metadata, short[] values, short fillValue, DataOutputStream out)
        throws IOException {
    int length = Array.getLength(values);
    int resolution = (int) Math.round(Math.sqrt(length));

    // Write tree header
    out.writeInt(resolution); // resolution
    out.writeShort(fillValue);
    out.writeInt(1); // cardinality
    out.writeLong(metadata.time); // Timestamp

    // Fetch the stock quad tree of the associated resolution
    StockQuadTree stockQuadTree = getOrCreateStockQuadTree(resolution);
    // Sort values by their respective Z-Order values in linear time
    short[] sortedValues = new short[length];
    for (int i = 0; i < length; i++)
        sortedValues[i] = values[stockQuadTree.r[i]];

    // Write all sorted values
    for (short v : sortedValues)
        out.writeShort(v);

    // Compute aggregate values for all nodes in the tree
    // Go in reverse ID order to ensure children are computed before parents
    Node[] nodes = new Node[stockQuadTree.nodesID.length];
    for (int iNode = stockQuadTree.nodesID.length - 1; iNode >= 0; iNode--) {
        // Initialize all aggregate values
        nodes[iNode] = new Node();

        int firstChildId = stockQuadTree.nodesID[iNode] * 4;
        int firstChildPos = Arrays.binarySearch(stockQuadTree.nodesID, firstChildId);
        boolean isLeaf = firstChildPos < 0;

        if (isLeaf) {
            for (int iVal = stockQuadTree.nodesStartPosition[iNode]; iVal < stockQuadTree.nodesEndPosition[iNode]; iVal++) {
                short value;
                Object val = Array.get(sortedValues, iVal);
                if (val instanceof Short) {
                    value = (Short) val;
                } else {
                    throw new RuntimeException("Cannot handle values of type " + val.getClass());
                }
                if (value != fillValue)
                    nodes[iNode].accumulate(value);
            }
        } else {
            // Compute from the four children
            for (int iChild = 0; iChild < 4; iChild++) {
                int childPos = firstChildPos + iChild;
                nodes[iNode].accumulate(nodes[childPos]);
            }
        }
    }

    // Write nodes to file in sorted order
    for (int iNode = 0; iNode < nodes.length; iNode++)
        nodes[iNode].write(out);
}

From source file:org.apache.hadoop.mapreduce.v2.hs.HistoryServerLeveldbStateStoreService.java

@Override
public void storeToken(MRDelegationTokenIdentifier tokenId, Long renewDate) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Storing token " + tokenId.getSequenceNumber());
    }/*from  w w w .  ja va 2  s. co  m*/

    ByteArrayOutputStream memStream = new ByteArrayOutputStream();
    DataOutputStream dataStream = new DataOutputStream(memStream);
    try {
        tokenId.write(dataStream);
        dataStream.writeLong(renewDate);
        dataStream.close();
        dataStream = null;
    } finally {
        IOUtils.cleanup(LOG, dataStream);
    }

    String dbKey = getTokenDatabaseKey(tokenId);
    try {
        db.put(bytes(dbKey), memStream.toByteArray());
    } catch (DBException e) {
        throw new IOException(e);
    }
}

From source file:com.rapidminer.cryptography.hashing.DigesterProvider.java

/**
 * Writes the provided value to the provided {@link DataOutputStream}.
 *//*from   ww w.  j av  a 2  s.c  om*/
private void writeBytes(Object value, DataOutputStream dos) throws IOException, JEPFunctionException {
    if (value instanceof String) {
        dos.writeUTF((String) value);
    } else if (value instanceof Integer) {
        dos.writeInt((int) value);
    } else if (value instanceof Long) {
        dos.writeLong((long) value);
    } else if (value instanceof Float) {
        dos.writeFloat((float) value);
    } else if (value instanceof GregorianCalendar) {
        dos.writeLong(((GregorianCalendar) value).getTimeInMillis());
    } else if (value instanceof Date) {
        dos.writeLong(((Date) value).getTime());
    } else if (value instanceof Double) {
        dos.writeDouble((double) value);
    } else if (value instanceof UnknownValue) {
        dos.writeDouble(Double.NaN);
    } else {
        // should not happen
        throw new JEPFunctionException("Unknown input type: " + value.getClass());
    }
}

From source file:org.apache.hadoop.mapreduce.v2.hs.HistoryServerFileSystemStateStoreService.java

private byte[] buildTokenData(MRDelegationTokenIdentifier tokenId, Long renewDate) throws IOException {
    ByteArrayOutputStream memStream = new ByteArrayOutputStream();
    DataOutputStream dataStream = new DataOutputStream(memStream);
    try {/*from   ww  w . j av  a 2s .c o m*/
        tokenId.write(dataStream);
        dataStream.writeLong(renewDate);
        dataStream.close();
        dataStream = null;
    } finally {
        IOUtils.cleanup(LOG, dataStream);
    }
    return memStream.toByteArray();
}

From source file:de.burlov.ultracipher.core.Database.java

public String computeChecksum() {
    DigestOutputStream digest = new DigestOutputStream(new RIPEMD160Digest());
    DataOutputStream out = new DataOutputStream(digest);

    try {/*from   w w  w .  ja v  a 2  s .  c  o m*/
        for (Entry<String, Long> entry : deletedEntries.entrySet()) {
            out.writeUTF(entry.getKey());
            out.writeLong(entry.getValue());
        }
        for (DataEntry entry : entries.values()) {
            out.writeUTF(entry.getId());
            out.writeUTF(entry.getName());
            out.writeUTF(entry.getTags());
            out.writeUTF(entry.getText());
        }
        out.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new String(Hex.encode(digest.getDigest()));
}