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.csc.phynixx.loggersystem.logrecord.XADataLogger.java

/**
 *
 *
 * @param dataRecorder//from w  w w .  jav a  2s  . c om
 *            DataRecorder that uses /operates on the current physical
 *            logger
 *
 * @param message
 *            message to be written
 * @throws IOException
 */
void writeData(PhynixxXADataRecorder dataRecorder, IDataRecord message) throws IOException {
    DataOutputStream io = null;
    try {

        ByteArrayOutputStream byteIO = new ByteArrayOutputStream(HEADER_SIZE);
        io = new DataOutputStream(byteIO);

        io.writeLong(message.getXADataRecorderId());
        io.writeInt(message.getOrdinal().intValue());
        byte[] header = byteIO.toByteArray();

        byte[][] data = message.getData();
        byte[][] content = null;
        if (data == null) {
            content = new byte[][] { header };
        } else {
            content = new byte[data.length + 1][];
            content[0] = header;
            for (int i = 0; i < data.length; i++) {
                content[i + 1] = data[i];
            }
        }

        try {
            this.dataLogger.write(message.getLogRecordType().getType(), content);
        } catch (Exception e) {
            throw new DelegatedRuntimeException(
                    "writing message " + message + "\n" + ExceptionUtils.getStackTrace(e), e);
        }
    } finally {
        if (io != null) {
            io.close();
        }
    }

    // Add the messageSequence to the set og messageSequences ...
}

From source file:pcap.application.PcapApplicationTest.java

/**
 * Create temporary pcap file with little endian data
 * @param name/*from www .j a v a 2s  .  c o  m*/
 * @return File
 * @throws IOException
 */
public File createTempPCapLittleEndian(String name) throws IOException {
    final File testPCap = tempFolder.newFile(name + PCAP_EX);
    DataOutputStream os = new DataOutputStream(new FileOutputStream(testPCap));
    try {
        long[] bin = { 0xd4c3b2a102000400L, 0x0000000000000000L, 0xffff000001000000L, 0x7934c242cd710800L,
                0x080000004b000000L, 0x1234ffff0000121aL };
        for (int i = 0; i < bin.length; i++) {
            os.writeLong(bin[i]);
        }

    } finally {
        os.close();
    }
    return testPCap;
}

From source file:pcap.application.PcapApplicationTest.java

/**
 * Create temporary pcap file with big endian data
 * @param name//from   w  ww  .  j a v a2 s  .co  m
 * @return File
 * @throws IOException
 */
public File createTempPCapBigEndian(String name) throws IOException {
    final File testPCap = tempFolder.newFile(name + PCAP_EX);
    DataOutputStream os = new DataOutputStream(new FileOutputStream(testPCap));
    try {
        long[] bin = { 0xa1b2c3d400020004L, 0x0000000000000000L, 0x0000ffff00000001L, 0x42c23479000871cdL,
                0x000000080000004bL, 0x1234ffff0000121aL };
        for (int i = 0; i < bin.length; i++) {
            os.writeLong(bin[i]);
        }

    } finally {
        os.close();
    }
    return testPCap;
}

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

@Override
public <K, V> boolean replace(final K key, final V value, final Serializer<K> keySerializer,
        final Serializer<V> valueSerializer, final long revision) throws IOException {
    return withCommsSession(session -> {
        validateProtocolVersion(session, 2);

        final DataOutputStream dos = new DataOutputStream(session.getOutputStream());
        dos.writeUTF("replace");

        serialize(key, keySerializer, dos);
        dos.writeLong(revision);
        serialize(value, valueSerializer, dos);

        dos.flush();/*from   w ww. j  av  a  2  s  . c om*/

        // read response
        final DataInputStream dis = new DataInputStream(session.getInputStream());
        return dis.readBoolean();
    });
}

From source file:org.eurekastreams.server.persistence.mappers.cache.testhelpers.SimpleMemoryCache.java

/**
 * Get the byte[] from a ArrayList&lt;Long&gt;.
 *
 * @param inListOfLongs/*w  ww  . j  a v a2  s.  co m*/
 *            the list of longs to convert
 * @return the byte[] representation of the ArrayList
 * @throws IOException thrown if any errors encountered
 */
protected byte[] getBytesFromList(final List<Long> inListOfLongs) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(bytes);
    byte[] toReturn = null;
    try {
        for (Long oneLong : inListOfLongs) {
            out.writeLong(oneLong);
            out.flush();
        }

        toReturn = bytes.toByteArray();
    } finally {
        out.close();
    }

    return toReturn;
}

From source file:RealFunctionValidation.java

public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out,
        final Class<?> type) throws IOException {

    if (!type.isPrimitive()) {
        throw new IllegalArgumentException("type must be primitive");
    }/*  w w  w  .j  a  va 2 s.c o  m*/
    if (type.equals(Boolean.TYPE)) {
        final boolean x = in.readBoolean();
        out.writeBoolean(x);
        return Boolean.valueOf(x);
    } else if (type.equals(Byte.TYPE)) {
        final byte x = in.readByte();
        out.writeByte(x);
        return Byte.valueOf(x);
    } else if (type.equals(Character.TYPE)) {
        final char x = in.readChar();
        out.writeChar(x);
        return Character.valueOf(x);
    } else if (type.equals(Double.TYPE)) {
        final double x = in.readDouble();
        out.writeDouble(x);
        return Double.valueOf(x);
    } else if (type.equals(Float.TYPE)) {
        final float x = in.readFloat();
        out.writeFloat(x);
        return Float.valueOf(x);
    } else if (type.equals(Integer.TYPE)) {
        final int x = in.readInt();
        out.writeInt(x);
        return Integer.valueOf(x);
    } else if (type.equals(Long.TYPE)) {
        final long x = in.readLong();
        out.writeLong(x);
        return Long.valueOf(x);
    } else if (type.equals(Short.TYPE)) {
        final short x = in.readShort();
        out.writeShort(x);
        return Short.valueOf(x);
    } else {
        // This should never occur.
        throw new IllegalStateException();
    }
}

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

public void serialize(IColumn column, DataOutputStream dos) throws IOException {
    SuperColumn superColumn = (SuperColumn) column;
    dos.writeUTF(superColumn.name());/*from   w w w .  j av  a 2s  . c o m*/
    dos.writeLong(superColumn.getMarkedForDeleteAt());

    Collection<IColumn> columns = column.getSubColumns();
    int size = columns.size();
    dos.writeInt(size);

    /*
     * Add the total size of the columns. This is useful
     * to skip over all the columns in this super column
     * if we are not interested in this super column.
    */
    dos.writeInt(superColumn.getSizeOfAllColumns());
    // dos.writeInt(superColumn.size());

    for (IColumn subColumn : columns) {
        Column.serializer().serialize(subColumn, dos);
    }
}

From source file:cn.edu.wyu.documentviewer.model.DocumentInfo.java

@Override
public void write(DataOutputStream out) throws IOException {
    out.writeInt(VERSION_SPLIT_URI);
    DurableUtils.writeNullableString(out, authority);
    DurableUtils.writeNullableString(out, documentId);
    DurableUtils.writeNullableString(out, mimeType);
    DurableUtils.writeNullableString(out, displayName);
    out.writeLong(lastModified);
    out.writeInt(flags);//w  w w. j a  va2  s  . com
    DurableUtils.writeNullableString(out, summary);
    out.writeLong(size);
    out.writeInt(icon);
}

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

private static void writeObject(final DataOutputStream outputStream, final byte type, final Object value)
        throws IOException {

    switch (type) {

    case 0://  ww  w.ja  v  a2  s  . c  o  m
    case 1:
        outputStream.writeByte((byte) value);
        break;

    case 2:
    case 3:
        outputStream.writeShort((short) value);
        break;

    case 4:
    case 5:
        outputStream.writeInt((int) value);
        break;

    case 6:
    case 7:
        outputStream.writeLong((long) value);
        break;

    case 8:
    case 9:
        outputStream.writeFloat((float) value);
        break;

    case 10:
    case 11:
        outputStream.writeDouble((double) value);
        break;

    case 12:
    case 13:
        outputStream.writeChar((char) value);
        break;

    case 14:
    case 15:
        serializeData(outputStream, ((String) value).getBytes("UTF-8"));

        // this doesn't work with very long strings
        //outputStream.writeUTF((String)value);
        break;

    case 16:
    case 17:
        outputStream.writeBoolean((boolean) value);
        break;
    }
}

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

public void serialize(IColumn column, DataOutputStream dos) throws IOException {
    SuperColumn superColumn = (SuperColumn) column;
    dos.writeUTF(superColumn.name());/*from   ww  w  .  j  a  v  a  2  s .co  m*/
    dos.writeInt(superColumn.getLocalDeletionTime());
    dos.writeLong(superColumn.getMarkedForDeleteAt());

    Collection<IColumn> columns = column.getSubColumns();
    int size = columns.size();
    dos.writeInt(size);

    dos.writeInt(superColumn.getSizeOfAllColumns());
    for (IColumn subColumn : columns) {
        Column.serializer().serialize(subColumn, dos);
    }
}