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:com.nxp.ltsm.ltsmclient.tools.VCDescriptionFile.java

public static byte[] CreatePersonalizeData(byte[] VCData, String pkgName, String appShaName, short VC_Entry,
        Context context) {/* w ww.ja  va2s .c  o m*/
    String TAG = "VCDescriptionFile:cCreatePersonalizeData";
    Log.i(TAG, "Enter");
    int i = VCData.length;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] VC_EntryBytes = Utils.shortToByteArr(VC_Entry);
    try {
        out.write(createTlv(0x4F, Hex.decodeHex(appShaName.toCharArray())));
        out.write(createTlv(0x40, VC_EntryBytes));
        out.write(Utils.append(VCData,
                createTlv(0xC1, Hex.decodeHex(Utils.shaSignature(pkgName, context).toCharArray()))));
        return (createTlv(0x73, out.toByteArray()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Vector<byte[]> split(int command, byte[] dataToTransport, int chunksize) {
    Vector<byte[]> result = new Vector<byte[]>();
    if (chunksize < 8) {
        throw new RuntimeException("Invalid chunk size");
    }//  w  ww  . ja  v  a 2s.c om
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int remaining_length = dataToTransport.length;
    int offset = 0;
    int seq = 0;
    boolean firstPacket = true;

    while (remaining_length > 0) {
        int l = 0;
        if (!firstPacket) {
            baos.write(seq);
            l = Math.min(chunksize - 1, remaining_length);
        } else {
            baos.write(command);
            // first packet has the total transport length
            baos.write(remaining_length >> 8);
            baos.write(remaining_length);
            l = Math.min(chunksize - 3, remaining_length);
        }
        baos.write(dataToTransport, offset, l);
        remaining_length -= l;
        offset += l;
        result.add(baos.toByteArray());
        baos.reset();
        if (!firstPacket) {
            seq++;
        }
        firstPacket = false;
    }

    return result;
}

From source file:com.nxp.ltsm.ltsmclient.tools.VCDescriptionFile.java

public static byte[] formVCList(int VCEntry, String AppName) {
    String TAG = "VCDescriptionFile:FormVCList";
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] VC_EntryBytes = Utils.shortToByteArr((short) VCEntry);
    try {//from  w  ww.  j  av  a  2s .  com
        out.write(createTlv(0x40, VC_EntryBytes));
        out.write(createTlv(0x4F, AppName.getBytes("UTF-8")));
        return createTlv(0x61, out.toByteArray());

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.xeiam.xchange.mtgox.v2.service.streaming.SocketMessageFactory.java

private static byte[] fromHexString(String hex) {

    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    for (int i = 0; i < hex.length(); i += 2) {
        int b = Integer.parseInt(hex.substring(i, i + 2), 16);
        bas.write(b);
    }//from ww w .  j  a  v  a 2 s. c o m

    return bas.toByteArray();
}

From source file:com.microsoft.tfs.core.httpclient.HttpParser.java

/**
 * Return byte array from an (unchunked) input stream. Stop reading when
 * <tt>"\n"</tt> terminator encountered If the stream ends before the line
 * terminator is found, the last part of the string will still be returned.
 * If no input data available, <code>null</code> is returned.
 *
 * @param inputStream/*from  w  w w.  j av a  2s .  c  om*/
 *        the stream to read from
 *
 * @throws IOException
 *         if an I/O problem occurs
 * @return a byte array from the stream
 */
public static byte[] readRawLine(final InputStream inputStream) throws IOException {
    LOG.trace("enter HttpParser.readRawLine()");

    final ByteArrayOutputStream buf = new ByteArrayOutputStream();
    int ch;
    while ((ch = inputStream.read()) >= 0) {
        buf.write(ch);
        if (ch == '\n') { // be tolerant (RFC-2616 Section 19.3)
            break;
        }
    }
    if (buf.size() == 0) {
        return null;
    }
    return buf.toByteArray();
}

From source file:org.ardverk.daap.bio.HttpParser.java

/**
 * Return byte array from an (unchunked) input stream. Stop reading when
 * <tt>"\n"</tt> terminator encountered If the stream ends before the line
 * terminator is found, the last part of the string will still be returned.
 * If no input data available, <code>null</code> is returned.
 * /*from  ww w .  ja  va2  s  .  c om*/
 * @param inputStream
 *            the stream to read from
 * 
 * @throws IOException
 *             if an I/O problem occurs
 * @return a byte array from the stream
 */
public static byte[] readRawLine(InputStream inputStream) throws IOException {
    LOG.trace("enter HttpParser.readRawLine()");

    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    int ch;
    while ((ch = inputStream.read()) >= 0) {
        buf.write(ch);
        if (ch == '\n') { // be tolerant (RFC-2616 Section 19.3)
            break;
        }
    }
    if (buf.size() == 0) {
        return null;
    }
    return buf.toByteArray();
}

From source file:brainleg.app.util.AppWeb.java

private static String readFrom(InputStream is) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int c;/*w  w w . ja  va 2 s . c om*/
    while ((c = is.read()) != -1) {
        out.write(c);
    }
    String s = out.toString();
    out.close();
    return s;
}

From source file:halive.shootinoutside.common.core.game.map.GameMap.java

public static GameMap createFromByteArray(byte[] b) throws IOException, ParseException {
    ByteArrayInputStream in = new ByteArrayInputStream(b);
    GZIPInputStream input = new GZIPInputStream(in);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int j;/*  ww w. ja v  a 2 s.  c o  m*/
    while ((j = input.read()) != -1) {
        out.write(j);
    }
    String s = new String(out.toByteArray());
    return loadGameMapFromJSONString(s);
}

From source file:com.monitor.baseservice.utils.XCodeUtil.java

public synchronized static byte[] loadBytes(String name) throws IOException {
    FileInputStream in = null;//from w  w w  . ja va  2s  .co m
    in = new FileInputStream(name);
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        int ch;
        while ((ch = in.read()) != -1) {
            buffer.write(ch);
        }
        return buffer.toByteArray();
    } finally {
        in.close();
    }
}

From source file:Main.java

public static byte[] decodeQuotedPrintable(final byte[] bytes) {
    if (bytes == null) {
        return null;
    }/*ww w. j  a v  a2s . c om*/
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    for (int i = 0; i < bytes.length; i++) {
        final int b = bytes[i];
        if (b == '=') {
            try {
                final int u = Character.digit((char) bytes[++i], 16);
                final int l = Character.digit((char) bytes[++i], 16);
                buffer.write((char) ((u << 4) + l));
            } catch (Exception e) {
                //                    FileLog.e("tmessages", e);
                return null;
            }
        } else {
            buffer.write(b);
        }
    }
    byte[] array = buffer.toByteArray();
    try {
        buffer.close();
    } catch (Exception e) {
        //            FileLog.e("tmessages", e);
    }
    return array;
}