Merge "change fileinputstream to filechannel" into main am: b7bb53d392
am: 23b0cba8d6
Original change: https://android-review.googlesource.com/c/platform/build/+/3205700 Change-Id: I5f736f7952dd791bc2a330ef6a0b56917a7d8987 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -19,9 +19,10 @@ package android.aconfig.storage;
|
|||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.nio.MappedByteBuffer;
|
import java.nio.MappedByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public class StorageInternalReader {
|
public class StorageInternalReader {
|
||||||
@@ -69,16 +70,15 @@ 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;
|
FileChannel channel = null;
|
||||||
try {
|
try {
|
||||||
stream = new FileInputStream(file);
|
channel = FileChannel.open(Paths.get(file), StandardOpenOption.READ);
|
||||||
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 {
|
} finally {
|
||||||
quietlyDispose(stream);
|
quietlyDispose(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user