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:com.ning.arecibo.util.timeline.times.TimesAndSamplesCoder.java

public static byte[] combineTimesAndSamples(final byte[] times, final byte[] samples) {
    final int totalSamplesSize = 4 + times.length + samples.length;
    final ByteArrayOutputStream baStream = new ByteArrayOutputStream(totalSamplesSize);
    final DataOutputStream outputStream = new DataOutputStream(baStream);
    try {//from w w  w  .jav  a2 s .  c o  m
        outputStream.writeInt(times.length);
        outputStream.write(times);
        outputStream.write(samples);
        outputStream.flush();
        return baStream.toByteArray();
    } catch (IOException e) {
        throw new IllegalStateException(String.format(
                "Exception reading timeByteCount in TimelineChunkMapper.map() for times %s, samples %s",
                Hex.encodeHex(times), Hex.encodeHex(samples)), e);
    }
}

From source file:org.apache.accumulo.core.crypto.CryptoUtils.java

/**
 * Write the decryption parameters to the DataOutputStream
 *///from  www  .  j  av a  2  s .  c om
public static void writeParams(byte[] decryptionParams, DataOutputStream out) throws IOException {
    Objects.requireNonNull(decryptionParams);
    Objects.requireNonNull(out);
    out.writeInt(decryptionParams.length);
    out.write(decryptionParams);
}

From source file:Main.java

public static byte[] createAuthenticationDigest(String passcode, long t1, double q1)
        throws IOException, NoSuchAlgorithmException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    DataOutputStream out = new DataOutputStream(baos);
    byte[] digest = createDigest(passcode, t1, q1);
    out.writeLong(t1);/*from w  ww .j  a v a  2  s .  c o  m*/
    out.writeDouble(q1);
    out.writeInt(digest.length);
    out.write(digest);
    out.flush();
    return baos.toByteArray();
}

From source file:TestPipes.java

public static void writeData(OutputStream os) {
    try {/*w ww.  j  av a2s  .c  om*/
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(os));

        int[] numArray = { 1, 2, 3, 4, 5 };

        for (int i = 0; i < numArray.length; i++) {
            out.writeInt(numArray[i]);
        }

        out.flush();

        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.opensoc.json.serialization.JSONEncoderHelper.java

public static void putString(DataOutputStream data, String str) throws IOException {
    // String ID is 1
    data.writeByte(JSONKafkaSerializer.StringID);
    data.writeInt(str.length());
    data.write(str.getBytes());//from w  w w.ja va  2  s  .co  m

}

From source file:Main.java

public static void writeInts(String file, int[] ints) throws IOException {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 4 * 1024));
    try {//from  ww  w .  j av a 2 s  .c  o m
        int len = ints.length;
        out.writeInt(len);
        for (int i = 0; i < len; i++) {
            out.writeInt(ints[i]);
        }
    } finally {
        out.close();
    }
}

From source file:Main.java

public static void writeFloats(String file, float[] floats) throws IOException {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 4 * 1024));
    try {/*from  w w  w.  j av  a 2  s. co m*/
        int len = floats.length;
        out.writeInt(len);
        for (int i = 0; i < len; i++) {
            out.writeFloat(floats[i]);
        }
    } finally {
        out.close();
    }
}

From source file:Main.java

public static void writeSettings(String file, Object... objs) throws IOException {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 1024));
    try {//w  ww.ja v a2 s  . c o m
        out.writeInt(objs.length);
        for (Object obj : objs) {
            char cl;
            if (obj instanceof Byte) {
                cl = 'Y';
            } else {
                cl = obj.getClass().getSimpleName().charAt(0);
            }

            out.writeChar(cl);
            if (obj instanceof String) {
                out.writeUTF((String) obj);
            } else if (obj instanceof Float) {
                out.writeFloat((Float) obj);
            } else if (obj instanceof Double) {
                out.writeDouble((Double) obj);
            } else if (obj instanceof Integer) {
                out.writeInt((Integer) obj);
            } else if (obj instanceof Long) {
                out.writeLong((Long) obj);
            } else if (obj instanceof Boolean) {
                out.writeBoolean((Boolean) obj);
            } else {
                throw new IllegalStateException("Unsupported type");
            }
        }
    } finally {
        out.close();
    }
}

From source file:org.apache.reef.io.data.loading.impl.DistributedDataSetPartitionSerializer.java

public static String serialize(final DistributedDataSetPartition partition) {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        final DataOutputStream daos = new DataOutputStream(baos);
        daos.writeUTF(partition.getPath());
        daos.writeUTF(partition.getLocation());
        daos.writeInt(partition.getDesiredSplits());
        return Base64.encodeBase64String(baos.toByteArray());
    } catch (final IOException e) {
        throw new RuntimeException("Unable to serialize distributed data partition", e);
    }/*from  w  w w . ja v  a2  s  .com*/
}

From source file:org.mrgeo.utils.StringUtils.java

public static void write(String str, DataOutputStream stream) throws IOException {
    if (str == null) {
        stream.writeInt(-1);
    } else {//from  w  w  w  .  j a  v  a2 s  . c  o  m
        byte[] data = str.getBytes("UTF-8");
        stream.writeInt(data.length);
        stream.write(data);
    }
}