InputStream 转为 Byte

来源:互联网 发布:mac xquartz怎么用 编辑:程序博客网 时间:2024/05/21 08:41
public class Utils {  public static byte[] getBytes(InputStream is) throws IOException {    int len;    int size = 1024;    byte[] buf;    if (is instanceof ByteArrayInputStream) {      size = is.available();      buf = new byte[size];      len = is.read(buf, 0, size);    } else {      ByteArrayOutputStream bos = new ByteArrayOutputStream();      buf = new byte[size];      while ((len = is.read(buf, 0, size)) != -1)        bos.write(buf, 0, len);      buf = bos.toByteArray();    }    return buf;  }}

0 0
原创粉丝点击