Merge "close file stream" into main am: 39020e05c6
Original change: https://android-review.googlesource.com/c/platform/build/+/3199474 Change-Id: I8c40d1a77546c28e1ece9f5ae45e29ce6eb1a034 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -18,6 +18,7 @@ package android.aconfig.storage;
|
|||||||
|
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.nio.MappedByteBuffer;
|
import java.nio.MappedByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
@@ -68,13 +69,26 @@ public class StorageInternalReader {
|
|||||||
|
|
||||||
// Map a storage file given file path
|
// Map a storage file given file path
|
||||||
private static MappedByteBuffer mapStorageFile(String file) {
|
private static MappedByteBuffer mapStorageFile(String file) {
|
||||||
|
FileInputStream stream = null;
|
||||||
try {
|
try {
|
||||||
FileInputStream stream = new FileInputStream(file);
|
stream = new FileInputStream(file);
|
||||||
FileChannel channel = stream.getChannel();
|
FileChannel channel = stream.getChannel();
|
||||||
return channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
|
return channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AconfigStorageException(
|
throw new AconfigStorageException(
|
||||||
String.format("Fail to mmap storage file %s", file), e);
|
String.format("Fail to mmap storage file %s", file), e);
|
||||||
|
} finally {
|
||||||
|
quietlyDispose(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void quietlyDispose(Closeable closable) {
|
||||||
|
try {
|
||||||
|
if (closable != null) {
|
||||||
|
closable.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// no need to care, at least as of now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user