Example usage for java.io ByteArrayOutputStream toByteArray

List of usage examples for java.io ByteArrayOutputStream toByteArray

Introduction

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

Prototype

public synchronized byte[] toByteArray() 

Source Link

Document

Creates a newly allocated byte array.

Usage

From source file:com.dragome.callbackevictor.serverside.utils.RewritingUtils.java

public static byte[] toByteArray(InputStream in) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    copy(in, baos);/*from w  ww . ja  va 2 s  .c om*/
    return baos.toByteArray();
}

From source file:net.darkmist.alib.io.Serializer.java

public static <T extends Serializable> byte[] serializeToBytes(T obj) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    serializeToStream(obj, out);//w ww. j  a v  a2  s  .  c  o  m
    return out.toByteArray();
}

From source file:Main.java

public static byte[] getBytes(Object obj) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);/*from   ww w  . j  a  va2  s  .  c o  m*/
    out.flush();
    byte[] bytes = bout.toByteArray();
    bout.close();
    out.close();
    return bytes;
}

From source file:Main.java

/**
 *
 * @param inputStream/*from  w  w w.j  a  va 2 s . c  o m*/
 * @return
 */
public static byte[] readStream(InputStream inputStream) {
    byte[] ret = null;
    if (inputStream != null) {
        ByteArrayOutputStream bout = null;
        bout = new ByteArrayOutputStream();
        readStream(inputStream, bout);
        ret = bout.toByteArray();
        close(bout);
        bout = null;
    }
    return ret;
}

From source file:Main.java

public static byte[] combine(byte[]... elements) {
    try {/*from  w ww .  ja  v  a  2 s. c om*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        for (byte[] element : elements) {
            baos.write(element);
        }

        return baos.toByteArray();
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}

From source file:de.xwic.appkit.core.remote.client.IoUtil.java

/**
 * @param in/*from   w  w w.  j  a  v  a  2s. c o  m*/
 * @return
 * @throws IOException
 */
@SuppressWarnings("resource")
public static byte[] readBytes(final InputStream in) throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        copy(in, bos);
        return bos.toByteArray();
    } finally {
        close(bos);
    }
}

From source file:Main.java

/**
 * Convert input stream to string/*w  w w.  jav  a2  s .  c  o  m*/
 * 
 * @param input
 * @return
 * @throws IOException
 */
public static byte[] getBytes(InputStream input) throws IOException {
    byte[] buffer = new byte[8192];
    int bytesRead;
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    while ((bytesRead = input.read(buffer)) != -1) {
        output.write(buffer, 0, bytesRead);
    }
    return output.toByteArray();
}

From source file:com.grosscommerce.ICEcat.utilities.Downloader.java

public static byte[] download(String urlFrom, String login, String pwd) throws Throwable {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    download(urlFrom, login, pwd, os);//from w w w. ja v  a  2 s. c o m
    byte[] result = os.toByteArray();
    os.close();
    Logger.getLogger(Downloader.class.getName()).log(Level.INFO, "Downloaded {0} byte(s)",
            new Object[] { result.length });

    return result;
}

From source file:io.cloudslang.content.httpclient.build.CookieStoreBuilder.java

public static byte[] serialize(Object obj) throws IOException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream o = new ObjectOutputStream(b);
    o.writeObject(obj);/*from   w  ww  .  jav a  2 s  . c  o  m*/
    return b.toByteArray();
}

From source file:Main.java

public static @Nullable byte[] toByteArray(@Nullable Bitmap bitmap) {
    if (bitmap == null)
        return null;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    return stream.toByteArray();
}