复制InputStream流的方法


private static InputStream cloneInputStream(InputStream input) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = input.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
return new ByteArrayInputStream(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
posted @ 2019-05-30 16:13  迷茫于红尘  阅读(328)  评论(0编辑  收藏  举报