Java OutputStream Write writeStreamToArray(InputStream stream)

Here you can find the source of writeStreamToArray(InputStream stream)

Description

write Stream To Array

License

Open Source License

Declaration

public static byte[] writeStreamToArray(InputStream stream) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static byte[] writeStreamToArray(InputStream stream) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int length = 0;
        while ((length = stream.read(buffer)) != -1)
            baos.write(buffer, 0, length);
        return baos.toByteArray();
    }//from ww  w.jav  a2 s .c o  m
}

Related

  1. writeStreamCharwiseLimited(final Reader in, final Writer out, final int len)
  2. writeStreamFromString(String contents, OutputStream outputStream)
  3. writeStreamFromString(String serializePath)
  4. writeStreamInFile(File f, InputStream in)
  5. writeStreamText(OutputStream out, String text)
  6. writeStreamToStream(InputStream in, OutputStream out)
  7. writeStreamToStream(InputStream input, OutputStream output)
  8. writeStreamToStream(InputStream inputStream, OutputStream outputStream)