Java InputStream to Byte Array getBytesFromInputStream(InputStream is)

Here you can find the source of getBytesFromInputStream(InputStream is)

Description

get Bytes From Input Stream

License

Apache License

Declaration

private static byte[] getBytesFromInputStream(InputStream is) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static byte[] getBytesFromInputStream(InputStream is) throws IOException {
        try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
            byte[] buffer = new byte[0xFFFF];

            for (int len; (len = is.read(buffer)) != -1;)
                os.write(buffer, 0, len);

            os.flush();//  w  w  w .  jav  a2s.  co  m

            return os.toByteArray();
        }
    }
}

Related

  1. getBytes(InputStream stream)
  2. getBytes(InputStream stream)
  3. getBytesFromInputStream(InputStream inputStream)
  4. getBytesFromInputStream(InputStream inputStream)
  5. getBytesFromInputStream(InputStream inputStream)
  6. getBytesFromInputStream(InputStream is)
  7. getBytesFromStream(InputStream input)
  8. getBytesFromStream(InputStream inputStream)
  9. getBytesFromStream(InputStream is)