2013-06-29 1 views
1

나는 작동중인 Android 앱의 디스크에 비디오 파일 몇 개를 저장하기 위해 SimpleDiskCache 코드 (github link)를 사용하고 있습니다. 는 여기에 내가 캐시에 비디오 파일을 넣어하는 방법은 다음과 같습니다SimpleDiskCache inputStream 잘못된 숫자 형식

OutputStream fil = videoCache.openStream(newData.getObjectId().toLowerCase()); 
fil.write(videoInBytes); 
fil.flush(); 
fil.close(); 

을 그리고 여기에 내가 캐시에서 비디오 파일을 검색 할 코드입니다 :

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 (잘못된 파일 번호). 여기에 스택 추적이 있습니다 :

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) 

누군가 내가 잘못하고있는 아이디어가 있습니까? 감사합니다.

+0

이 대답은 어떻게됩니까? http://stackoverflow.com/questions/14584755/read-failed-ebadf-bad-file-number –

답변

2

입력 스트림이 사용되기 전에 닫혀진 것처럼 보입니다. 끝나면 snapshot.close()를 59 행에 주석 처리하고 입력 스트림을 닫아야합니다.

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(); 
    } 
}