你怎么读两次相同的输入流?有可能以某种方式复制它吗?
我需要从网上获取图像,在本地保存,然后返回保存的图像.我只是认为使用相同的流而不是为下载的内容启动新流然后再次读取它会更快.
我有一个文件的InputStream,我使用apache poi组件来读取它像这样:
POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
Run Code Online (Sandbox Code Playgroud)
问题是我需要多次使用相同的流,POIFSFileSystem在使用后关闭流.
从输入流缓存数据然后将更多输入流提供给不同的POIFSFileSystem的最佳方法是什么?
编辑1:
通过缓存我的意思是存储供以后使用,而不是作为加速应用程序的方法.最好是将输入流读入数组或字符串,然后为每次使用创建输入流?
编辑2:
很抱歉重新打开这个问题,但在桌面和Web应用程序中工作时条件有所不同.首先,我从tomcat web app中的org.apache.commons.fileupload.FileItem获取的InputStream不支持标记,因此无法重置.
其次,我希望能够将文件保存在内存中,以便在处理文件时更快地访问和减少io问题.
Is there anyway to reuse an inputStream by changing its content? (Without new statement).
For instance, I was able to something very close to my requirement, but not enough
In the following code I am using a SequenceInputStream, and everytime I am adding a new InputStream to that sequence.
But I would like to do the same thing by using the same inputStream (I don't care which implementation of InputStream).
I thought about mark()/reset() APIs, but …