mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
Attempt to guard against ExoCache corruption.
This commit is contained in:
parent
cfcbca6c95
commit
ed658b8e8d
3 changed files with 35 additions and 5 deletions
|
|
@ -61,8 +61,11 @@ public final class TeeDataSource implements DataSource {
|
|||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
upstream.close();
|
||||
dataSink.close();
|
||||
try {
|
||||
upstream.close();
|
||||
} finally {
|
||||
dataSink.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.google.android.exoplayer.C;
|
|||
import com.google.android.exoplayer.upstream.DataSink;
|
||||
import com.google.android.exoplayer.upstream.DataSpec;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
|
@ -115,11 +116,23 @@ public class CacheDataSink implements DataSink {
|
|||
}
|
||||
|
||||
private void closeCurrentOutputStream() throws IOException {
|
||||
if (outputStream != null) {
|
||||
if (outputStream == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
try {
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
outputStream.getFD().sync();
|
||||
success = true;
|
||||
} finally {
|
||||
Util.closeQuietly(outputStream);
|
||||
if (success) {
|
||||
cache.commitFile(file);
|
||||
} else {
|
||||
file.delete();
|
||||
}
|
||||
outputStream = null;
|
||||
cache.commitFile(file);
|
||||
file = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import android.text.TextUtils;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.HttpURLConnection;
|
||||
|
|
@ -129,6 +130,19 @@ public final class Util {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes an {@link OutputStream}, suppressing any {@link IOException} that may occur.
|
||||
*
|
||||
* @param outputStream The {@link OutputStream} to close.
|
||||
*/
|
||||
public static void closeQuietly(OutputStream outputStream) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts text to lower case using {@link Locale#US}.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue