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:Decoder.java

public static String packLicense(byte[] text, byte[] hash) throws Exception {
    try {// w w  w  .  j av a2  s  .  c o m
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dOut = new DataOutputStream(out);
        dOut.writeInt(text.length);
        dOut.write(text);
        dOut.write(hash);

        byte[] allData = out.toByteArray();
        String result = new String(Base64.encodeBase64(allData)).trim();

        result = result + 'X' + "0" + 2 + Integer.toString(result.length(), 31);
        return split(result);
    } catch (IOException e) {
        throw new Exception(e);
    }
}

From source file:Main.java

public static byte[] convertToB64(int[] a) {
    ByteArrayOutputStream os = new ByteArrayOutputStream(a.length * 4 + 2);
    try {/*ww w.  j a v  a 2  s.co m*/
        DataOutputStream dou = new DataOutputStream(os);
        for (int i = 0; i < a.length; i++)
            dou.writeInt(a[i]);
        return encode(os.toByteArray());
    } catch (Exception s) {
        return null;
    }
}

From source file:tachyon.io.Utils.java

public static void writeString(String str, DataOutputStream os) throws IOException {
    if (str == null) {
        os.writeInt(-1);
    } else {/*from  w ww.j  a v  a 2s .  c  o m*/
        os.writeInt(str.length());
        os.writeChars(str);
    }
}

From source file:PipedBytes.java

public static void writeStuff(OutputStream rawOut) {
    try {//from  w  w  w  .jav a 2s.c  om
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(rawOut));

        int[] data = { 82, 105, 99, 104, 97, 114, 100, 32, 72, 121, 100, 101 };

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

        out.flush();
        out.close();
    } catch (IOException x) {
        x.printStackTrace();
    }
}

From source file:tachyon.io.Utils.java

public static void writeByteBuffer(ByteBuffer buf, DataOutputStream os) throws IOException {
    if (buf == null) {
        os.writeInt(-1);
        return;/*  www .  ja va  2 s .  c o m*/
    }
    int len = buf.limit() - buf.position();
    os.writeInt(len);
    os.write(buf.array(), buf.position(), len);
}

From source file:tachyon.io.Utils.java

public static void writeByteBufferList(List<ByteBuffer> list, DataOutputStream os) throws IOException {
    if (list == null) {
        os.writeInt(-1);
        return;/*from  www. j  a v a 2s . c  om*/
    }
    os.writeInt(list.size());
    for (int k = 0; k < list.size(); k++) {
        writeByteBuffer(list.get(k), os);
    }
}

From source file:tachyon.io.Utils.java

public static void writeStringList(List<String> list, DataOutputStream os) throws IOException {
    if (list == null) {
        os.writeInt(-1);
        return;/*from  w  w w.ja  va2s  . c  o m*/
    }
    os.writeInt(list.size());
    for (int k = 0; k < list.size(); k++) {
        writeString(list.get(k), os);
    }
}

From source file:com.atlassian.extras.decoder.v2.Version2LicenseDecoder.java

public static String packLicense(byte[] text, byte[] hash) throws LicenseException {
    try {//from w w w  .ja v a 2  s. c  o m
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dOut = new DataOutputStream(out);
        dOut.writeInt(text.length);
        dOut.write(text);
        dOut.write(hash);

        byte[] allData = out.toByteArray();
        String result = new String(Base64.encodeBase64(allData)).trim();

        result = result + 'X' + "0" + 2 + Integer.toString(result.length(), 31);
        return split(result);
    } catch (IOException e) {
        throw new LicenseException(e);
    }
}

From source file:tachyon.io.Utils.java

public static void writeIntegerList(List<Integer> list, DataOutputStream os) throws IOException {
    if (list == null) {
        os.writeInt(-1);
        return;//from   ww w  . j  ava 2s .  co m
    }

    os.writeInt(list.size());
    for (int k = 0; k < list.size(); k++) {
        os.writeInt(list.get(k));
    }
}

From source file:org.locationtech.geomesa.bigtable.spark.BigtableInputFormatBase.java

public static String scanToString(BigtableExtendedScan scan) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] table = scan.getAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME);
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeInt(table.length);
    dos.write(table);// w  w  w  .j av  a2s  .  c o  m
    scan.getRowSet().writeTo(dos);
    dos.flush();
    return Base64.getEncoder().encodeToString(baos.toByteArray());
}