Java InputStream to Byte Array getBytes(InputStream is, int max_len)

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

Description

get Bytes

License

Apache License

Declaration

public static byte[] getBytes(InputStream is, int max_len) 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 {
    public static byte[] getBytes(InputStream is, int max_len) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(max_len);
        for (int i = 0, b = is.read(); b >= 0 && i < max_len; b = is.read(), ++i)
            baos.write(b);/*  ww w.j a  v  a  2  s  . c o m*/
        return baos.toByteArray();
    }

    public static byte[] getBytes(InputStream is) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for (int b = is.read(); b >= 0; b = is.read())
            baos.write(b);
        return baos.toByteArray();
    }
}

Related

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