关于inputStream 对象重复使用的解决方法
2017-04-24 11:52
453 查看
/** * 读取输入流数据 * //此方法是用于缓存H5网络请求数据,解决inputStream对象不能重复复用的问题 */ public static byte[] streamToData(InputStream uristream) { ByteArrayOutputStream outStream = null; try { outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = uristream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } return outStream.toByteArray(); } catch (Exception e) { return null; } finally { try { if(uristream !=null) { uristream.close(); } if (outStream != null) { outStream.close(); } } catch (IOException e) { e.printStackTrace(); } } }
byte[] data = FileUtils.streamToData(inputstream);//把需要复用的inputStream保存为data
InputStream in1 = new ByteArrayInputStream(data) InputStream in2 = new ByteArrayInputStream(data)
相关文章推荐
- 关于使用ASP.NE 1.1发送电子邮件时出现的 未能访问“CDO.Message”对象 的错误的解决方法
- 关于使用jquery时,ie8下提示对象不支持的属性或方法的解决办法
- Java使用ObjectOutputStream和ObjectInputStream序列号对象报java.io.EOFException异常的解决方法
- 关于重复使用InputStream对象的
- 我的Java开发学习之旅------>Java使用ObjectOutputStream和ObjectInputStream序列号对象报java.io.EOFException异常的解决方法
- 关于asp.net网站发布后,使用登录控件和注册控件时出现“数据库只读,无法进行数据更新”的解决方法
- 关于submit() 对象不支持此属性或方法的解决方法
- 关于使用sql删除数据库重复的数据的方法整理:
- 关于使用VS.Net2003调试器出现的问题及相关解决方法 (转)
- 使用PageMethods老是出现"PageMethods未定义"或"对象不支持此属性或方法"的解决方法
- 关于在使用rowid和rownum时遇到ORA-01446错误的原因即解决方法。
- 关于javascript无法使用XPath的函数功能的解决方法
- 关于使用VS.Net2003调试器出现的问题及相关解决方法
- 关于IE7打开任何网页弹出[未处理的异常('对象不支持此属性或方法')发生在iexplorer.exe]错误调试框的解决办法
- 关于ASP.NET“操作必须使用一个可更新的查询”问题的解决方法
- 关于Struts2.0中重复提交问题的解决方法
- java中使用ObjectOutputStream和ObjectInputStream时产生的“invalid stream header”错误解决方法
- tcl/tk脚本中使用大量重复代码的解决方法
- 关于使用asp.net调试器出现的问题及相关解决方法
- 关于VS2005 无法使用切换到设计视图的解决方法(转)