stream To Bytes : Stream « File « Android

stream To Bytes


class Main {
  public static byte[] streamToBytes(InputStream is) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();   
        int i = -1;
        try {
          byte[] bytes = new byte[1024];
      while ((i = != -1) {
          baos.write(bytes, 0, i);
          bytes = new byte[1024];
      return baos.toByteArray();
    } catch (Exception e) {
    return null;



Related examples in the same category

1.Playing Back Audio Streams
2.Stream Proxy
3.Copy Stream
4.Ini File Stream Reader
5.Read InputStream fully to a string
6.Read Stream to byte array String From Stream
8.Read stream Fully
9.Read InputStream with ByteArrayOutputStream
10.get Resource As Stream, Loads the resource from classpath
11.InputStream to byte array, copy Reader and Writer,
12.InputStream that notifies listeners of its progress.
13.String to InputStream
14.Context.getFileStreamPath To String
16.Load/save Int Map Data
17.Write InputStream into a StringBuilder