Java InputStream to Byte Array getBytes(InputStream is)

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

Description

get Bytes

License

Apache License

Declaration

public static byte[] getBytes(InputStream is) 

Method Source Code


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

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

public class Main {
    public static byte[] getBytes(InputStream is) {
        try {/*from  w  w w.j a  v  a2s .  c om*/
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int nRead;
            byte[] data = new byte[16384];
            while ((nRead = is.read(data, 0, data.length)) != -1) {
                buffer.write(data, 0, nRead);
            }

            buffer.flush();
            System.out.println("byte: " + new String(buffer.toByteArray()));
            return buffer.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. getBytes(InputStream inputStream)
  2. getBytes(InputStream inputStream)
  3. getBytes(InputStream inputStream)
  4. getBytes(InputStream is)
  5. getBytes(InputStream is)
  6. getBytes(InputStream is)
  7. getBytes(InputStream is, int max_len)
  8. getBytes(InputStream stream)
  9. getBytes(InputStream stream)