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:org.apache.fontbox.ttf.TTFSubFont.java

private static void writeLongDateTime(DataOutputStream dos, Calendar calendar) throws IOException {
    // inverse operation of TTFDataStream.readInternationalDate()
    GregorianCalendar cal = new GregorianCalendar(1904, 0, 1);
    long millisFor1904 = cal.getTimeInMillis();
    long secondsSince1904 = (calendar.getTimeInMillis() - millisFor1904) / 1000L;
    dos.writeLong(secondsSince1904);
}

From source file:com.yahoo.omid.tso.persistence.BookKeeperStateLogger.java

/**
 * Initializes this logger object to add records. Implements the initialize 
 * method of the StateLogger interface./*  w  w w . j a  v  a 2  s  .  com*/
 * 
 * @param cb
 * @param ctx
 */

@Override
public void initialize(final LoggerInitCallback cb, Object ctx) throws LoggerException {
    TSOServerConfig config = ((BookKeeperStateBuilder.Context) ctx).config;

    /*
     * Create new ledger for adding records
     */
    try {
        bk = new BookKeeper(new ClientConfiguration(), zk);
    } catch (Exception e) {
        LOG.error("Exception while initializing bookkeeper", e);
        throw new LoggerException.BKOpFailedException();
    }

    bk.asyncCreateLedger(config.getEnsembleSize(), config.getQuorumSize(), BookKeeper.DigestType.CRC32,
            "flavio was here".getBytes(), new CreateCallback() {
                @Override
                public void createComplete(int rc, LedgerHandle lh, Object ctx) {
                    if (rc == BKException.Code.OK) {
                        try {
                            BookKeeperStateLogger.this.lh = lh;

                            ByteArrayOutputStream bos = new ByteArrayOutputStream();
                            DataOutputStream dos = new DataOutputStream(bos);
                            dos.writeLong(lh.getId());

                            zk.create(LoggerConstants.OMID_LEDGER_ID_PATH, bos.toByteArray(),
                                    Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
                                    new LedgerIdCreateCallback(cb, bos.toByteArray()), ctx);
                        } catch (IOException e) {
                            LOG.error("Failed to write to zookeeper. ", e);
                            cb.loggerInitComplete(Code.BKOPFAILED, BookKeeperStateLogger.this, ctx);
                        }
                    } else {
                        LOG.error("Failed to create ledger. " + BKException.getMessage(rc));
                        cb.loggerInitComplete(Code.BKOPFAILED, BookKeeperStateLogger.this, ctx);
                    }
                }
            }, ctx);
}

From source file:org.apache.hadoop.dfs.TestBlockReplacement.java

private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy,
        DatanodeInfo destination) throws IOException {
    Socket sock = new Socket();
    sock.connect(NetUtils.createSocketAddr(sourceProxy.getName()), FSConstants.READ_TIMEOUT);
    sock.setKeepAlive(true);//w ww .  j  a  va  2s.co m
    // sendRequest
    DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    out.writeShort(FSConstants.DATA_TRANSFER_VERSION);
    out.writeByte(FSConstants.OP_COPY_BLOCK);
    out.writeLong(block.getBlockId());
    out.writeLong(block.getGenerationStamp());
    Text.writeString(out, source.getStorageID());
    destination.write(out);
    out.flush();
    // receiveResponse
    DataInputStream reply = new DataInputStream(sock.getInputStream());

    short status = reply.readShort();
    if (status == FSConstants.OP_STATUS_SUCCESS) {
        return true;
    }
    return false;
}

From source file:org.apache.hadoop.hbase.io.hfile.TestFixedFileTrailer.java

private void serializeAsWritable(DataOutputStream output, FixedFileTrailer fft) throws IOException {
    BlockType.TRAILER.write(output);//from  w w w. j a va2 s  .c  om
    output.writeLong(fft.getFileInfoOffset());
    output.writeLong(fft.getLoadOnOpenDataOffset());
    output.writeInt(fft.getDataIndexCount());
    output.writeLong(fft.getUncompressedDataIndexSize());
    output.writeInt(fft.getMetaIndexCount());
    output.writeLong(fft.getTotalUncompressedBytes());
    output.writeLong(fft.getEntryCount());
    output.writeInt(fft.getCompressionCodec().ordinal());
    output.writeInt(fft.getNumDataIndexLevels());
    output.writeLong(fft.getFirstDataBlockOffset());
    output.writeLong(fft.getLastDataBlockOffset());
    Bytes.writeStringFixedSize(output, fft.getComparatorClassName(), MAX_COMPARATOR_NAME_LENGTH);
    output.writeInt(FixedFileTrailer.materializeVersion(fft.getMajorVersion(), fft.getMinorVersion()));
}

From source file:com.facebook.infrastructure.db.Column.java

public void serialize(IColumn column, DataOutputStream dos) throws IOException {
    dos.writeUTF(column.name());//from w  w w  .j a  v  a2 s . co  m
    dos.writeBoolean(column.isMarkedForDelete());
    dos.writeLong(column.timestamp());
    dos.writeInt(column.value().length);
    dos.write(column.value());
}

From source file:org.csc.phynixx.loggersystem.logrecord.XADataLogger.java

/**
 * start sequence writes the ID of the XADataLogger to identify the content
 * of the logger// ww w.  j av  a 2s . c om
 *
 * @param dataRecorder
 *            DataRecorder that uses /operates on the current physical
 *            logger
 *
 *
 *            deprecated
 */

private void writeStartSequence(IXADataRecorder dataRecorder) throws IOException, InterruptedException {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    try {
        DataOutputStream dos = new DataOutputStream(byteOut);
        dos.writeLong(dataRecorder.getXADataRecorderId());
        dos.flush();
    } finally {
        if (byteOut != null) {
            IOUtils.closeQuietly(byteOut);
        }
    }

    byte[][] startSequence = new byte[1][];
    startSequence[0] = byteOut.toByteArray();

    this.dataLogger.write(XALogRecordType.USER.getType(), startSequence);
}

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

protected void writeElementId(long id, DataOutputStream stream) throws IOException {
    stream.writeLong(id);
}

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

public void serialize(ReadCommand rm, DataOutputStream dos) throws IOException {
    dos.writeUTF(rm.table);//from  ww w .  j a va2s.c  o  m
    dos.writeUTF(rm.key);
    dos.writeUTF(rm.columnFamilyColumn);
    dos.writeInt(rm.start);
    dos.writeInt(rm.count);
    dos.writeLong(rm.sinceTimestamp);
    dos.writeBoolean(rm.isDigestQuery());
    dos.writeInt(rm.columnNames.size());
    if (rm.columnNames.size() > 0) {
        for (String cName : rm.columnNames) {
            dos.writeInt(cName.getBytes().length);
            dos.write(cName.getBytes());
        }
    }
}

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

public byte[] toByteArray() throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final DataOutputStream dos = new DataOutputStream(bos);
    try {//from w w w .j av  a 2  s.  com
        dos.writeInt(1); // serialized format version
        dos.writeLong(invisibleTimeoutTS); // invisible timeout
        dos.writeInt(body.length); // body size
        dos.write(body); // body
        return bos.toByteArray();
    } finally {
        IOUtils.closeQuietly(dos);
    }
}

From source file:org.apache.hadoop.hdfs.server.datanode.TestBlockReplacement.java

private boolean replaceBlock(Block block, DatanodeInfo source, DatanodeInfo sourceProxy,
        DatanodeInfo destination) throws IOException {
    Socket sock = new Socket();
    sock.connect(NetUtils.createSocketAddr(destination.getName()), HdfsConstants.READ_TIMEOUT);
    sock.setKeepAlive(true);/*from  w ww.  ja  v a2s  .  co m*/
    // sendRequest
    DataOutputStream out = new DataOutputStream(sock.getOutputStream());
    out.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION);
    out.writeByte(DataTransferProtocol.OP_REPLACE_BLOCK);
    out.writeLong(block.getBlockId());
    out.writeLong(block.getGenerationStamp());
    Text.writeString(out, source.getStorageID());
    sourceProxy.write(out);
    BlockTokenSecretManager.DUMMY_TOKEN.write(out);
    out.flush();
    // receiveResponse
    DataInputStream reply = new DataInputStream(sock.getInputStream());

    short status = reply.readShort();
    if (status == DataTransferProtocol.OP_STATUS_SUCCESS) {
        return true;
    }
    return false;
}