InputStream 转为 ByteArrayOutputStream
public Reader(InputStream input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
try {
while ((len = input.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
} catch (IOException e) {
throw new Exception("Illegal flow.");
} finally {
try {
input.close();
} catch (IOException e) {
logger.error("file stream shutdown failed.");
}
}
this.baos = baos;
}
ByteArrayOutputStream 转为 InputStream
private InputStream streamTran(ByteArrayOutputStream in) {
return new ByteArrayInputStream(in.toByteArray());
}
————————————————
版权声明:本文为CSDN博主「Mr-先森你好」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011067966/article/details/97757260