Java Byte Array from getBytes2(InputStream aStream)

Here you can find the source of getBytes2(InputStream aStream)

Description

Returns bytes for an input stream.

License

Open Source License

Declaration

public static byte[] getBytes2(InputStream aStream) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/*from  ww w . jav a 2 s.  c  o  m*/
     * Returns bytes for an input stream.
     */
    public static byte[] getBytes2(InputStream aStream) throws IOException {
        ByteArrayOutputStream bs = new ByteArrayOutputStream();
        byte chunk[] = new byte[8192];
        for (int len = aStream.read(chunk, 0, chunk.length); len > 0; len = aStream.read(chunk, 0, chunk.length))
            bs.write(chunk, 0, len);
        return bs.toByteArray();
    }
}

Related

  1. getBytes(String filePath, long startPos, long endPos)
  2. getBytes(String fileUrl)
  3. getBytes(String input)
  4. getBytes(ZipFile archive, ZipEntry entry)
  5. getBytes(ZipInputStream zipInputStream)
  6. getBytesAndClose(InputStream in)
  7. getBytesArrayFromFile(String fileName)
  8. getBytesASCII(String s)
  9. getBytesAsTempFile(byte[] bytes)