SimpleDiskCache的InputStream坏数字格式 [英] SimpleDiskCache inputStream bad number format
问题描述
我使用的是SimpleDiskCache code( GitHub的链接)缓存一些视频文件到磁盘Android应用我的工作。
以下是我把视频文件缓存:
I'm using the SimpleDiskCache code (github link) to cache a few video files to disk for an Android app I'm working. Here's how I put the video file to cache:
OutputStream fil = videoCache.openStream(newData.getObjectId().toLowerCase());
fil.write(videoInBytes);
fil.flush();
fil.close();
和这里的code,我想从缓存中获取视频文件:
And here's the code where I want to retrieve the video file from cache:
InputStream in = videoCache.getInputStream(newData.getObjectId().toLowerCase()).getInputStream();
File videoFile = Utils.createFile(Utils.TYPE_VIDEO_FILE);
OutputStream os = new FileOutputStream(videoFile);
IOUtils.copy(in, os);
os.close();
in.close();
唯一的问题是,我得到一个IOExption:读取失败:EBADF(错误的文件数)。这里的堆栈跟踪:
The only problem is that I get a IOExption: read failed: EBADF (Bad file number). Here's the stack trace:
06-29 18:47:21.422: W/System.err(19393): java.io.IOException: read failed: EBADF (Bad file number)
06-29 18:47:21.422: W/System.err(19393): at libcore.io.IoBridge.read(IoBridge.java:442)
06-29 18:47:21.430: W/System.err(19393): at java.io.FileInputStream.read(FileInputStream.java:179)
06-29 18:47:21.430: W/System.err(19393): at java.io.InputStream.read(InputStream.java:163)
06-29 18:47:21.430: W/System.err(19393): at com.google.api.client.util.ByteStreams.copy(ByteStreams.java:51)
06-29 18:47:21.430: W/System.err(19393): at com.google.api.client.util.IOUtils.copy(IOUtils.java:87)
06-29 18:47:21.430: W/System.err(19393): at com.google.api.client.util.IOUtils.copy(IOUtils.java:56)
06-29 18:47:21.430: W/System.err(19393): at com.licenta.mementoapp.datafragments.VideoFragment$1.done(VideoFragment.java:151)
有没有人有任何IDEEA我做错了什么?
谢谢!
Does anyone have any ideea what I'm doing wrong? Thanks!
推荐答案
似乎输入流正在使用之前关闭。你必须在注释行59 snapshot.close()调用,并自行关闭InputStream时,就大功告成了。
It seems that the input stream is closed before being used. You have to comment the snapshot.close() call at line 59 and close the inputstream yourself when you're done.
public InputStreamEntry getInputStream(String key) throws IOException {
DiskLruCache.Snapshot snapshot = diskLruCache.get(toInternalKey(key));
if (snapshot == null)
return null;
try {
return new InputStreamEntry(snapshot, readMetadata(snapshot));
} finally {
//snapshot.close();
}
}
这篇关于SimpleDiskCache的InputStream坏数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!