流转化为字节数组输出流

//转化流类型为字节数组输入流
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;
}

上一篇:Mysql安装、配置调优(二)


下一篇:Android高级架构师系统学习——Android-音频可视化,程序员怎样优雅度过35岁中年危机