Example usage for java.io ByteArrayOutputStream write

List of usage examples for java.io ByteArrayOutputStream write

Introduction

In this page you can find the example usage for java.io ByteArrayOutputStream write.

Prototype

public synchronized void write(int b) 

Source Link

Document

Writes the specified byte to this ByteArrayOutputStream .

Usage

From source file:Main.java

public static void writeBoolean(ByteArrayOutputStream baos, Boolean b) {
    if (b) {/*from   ww  w.j a v  a 2  s  .  co m*/
        baos.write(1);
    } else {
        baos.write(0);
    }
}

From source file:Main.java

public static byte[] concatByteArrays(byte[] a, byte[] b) {
    try {//w  w w . ja  v  a 2  s  .co m
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(a);
        outputStream.write(b);
        return outputStream.toByteArray();
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static byte[] getResponeData(int index, int resultCode, String response) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputStream.write(index);
    outputStream.write(0);/*  ww  w . j  av a 2 s.  c om*/
    outputStream.write(resultCode);
    try {
        outputStream.write(response.getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outputStream.toByteArray();
}

From source file:Main.java

public static byte[] getResponeData(int index, int resultCode, byte[] response) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputStream.write(index);
    outputStream.write(1);//from  w w w  .  j a  v a  2s  .  c  om
    outputStream.write(resultCode);
    try {
        outputStream.write(response);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outputStream.toByteArray();
}

From source file:Main.java

private static int finishBlock(int code, ByteArrayOutputStream sink, byte[] src, int begin, int end)
        throws IOException {
    sink.write(code);
    if (begin > -1)
        sink.write(src, begin, (end - begin) + 1);
    return (byte) 0x01;
}

From source file:Main.java

private static void writeIndentation(ByteArrayOutputStream os, int indent) {
    for (int j = 0; j < indent; j++) {
        os.write(' ');
        os.write(' ');
    }//from  w  ww .ja  va2s .  c  om
}

From source file:Main.java

public static byte[] toByteArray(int a, int b, int c, int d, int e, int f, int g, int h) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(32);
    baos.write(toByteArray(a));
    baos.write(toByteArray(b));//  w  w w. jav a2  s  . c om
    baos.write(toByteArray(c));
    baos.write(toByteArray(d));
    baos.write(toByteArray(e));
    baos.write(toByteArray(f));
    baos.write(toByteArray(g));
    baos.write(toByteArray(h));
    return baos.toByteArray();
}

From source file:com.klarna.hiverunner.builder.HiveResource.java

private static ByteArrayOutputStream createOutputStream(byte[] data) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(data);
    baos.close();// www.  jav  a2  s  .  c  o m
    return baos;
}

From source file:Main.java

public static byte[] padding(byte[] source) throws Exception {
    if (source.length >= 0x2000000000000000l) {
        throw new Exception();
    }//from w w w . j  av  a2  s . com
    long l = source.length * 8;
    long k = 448 - (l + 1) % 512;
    if (k < 0) {
        k = k + 512;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(source);
    baos.write(FirstPadding);
    long i = k - 7;
    while (i > 0) {
        baos.write(ZeroPadding);
        i -= 8;
    }
    baos.write(long2bytes(l));
    return baos.toByteArray();
}

From source file:Main.java

/**
 * @param context//  w  w  w  .j  av  a 2s.c o  m
 * @param filePath file path relative to assets, like request_init1/search_index.json
 * @return
 */
public static String readAssert(Context context, String filePath) {
    try {
        if (filePath.startsWith(File.separator)) {
            filePath = filePath.substring(File.separator.length());
        }
        AssetManager assetManager = context.getAssets();
        InputStream inputStream = assetManager.open(filePath);
        DataInputStream stream = new DataInputStream(inputStream);
        int length = stream.available();
        byte[] buffer = new byte[length];
        stream.readFully(buffer);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byteArrayOutputStream.write(buffer);
        stream.close();
        return byteArrayOutputStream.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}