其他分享
首页 > 其他分享> > 流转化为字节数组输出流

流转化为字节数组输出流

作者:互联网

//转化流类型为字节数组输入流
private ByteArrayInputStream socketToByteByStream(InputStream inputStream) {
ByteArrayInputStream byteArrayInputStream = null;
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = null;
int len = 0;
byte[] buf = new byte[2048];
while ((len = bufferedInputStream.read(buf)) != -1) {
byteArrayOutputStream.write(buf, 0, len);
}
byteArrayOutputStream.flush();
buffer = byteArrayOutputStream.toByteArray();
byteArrayInputStream = new ByteArrayInputStream(buffer);
} catch (IOException e) {
e.printStackTrace();
}
return byteArrayInputStream;
}

标签:输出,字节,buffer,len,byteArrayInputStream,数组,byteArrayOutputStream,new,ByteArrayInpu
来源: https://www.cnblogs.com/2027472755-even/p/15817663.html