Merge "Correct the blobstore Session.openWrite() API usage in tests." into rvc-dev

This commit is contained in:
Sudheer Shanka
2020-06-22 21:40:50 +00:00
committed by Android (Google) Code Review
2 changed files with 11 additions and 4 deletions

View File

@@ -153,7 +153,14 @@ public class DummyBlobData {
public void writeToSession(BlobStoreManager.Session session, public void writeToSession(BlobStoreManager.Session session,
long offsetBytes, long lengthBytes) throws Exception { long offsetBytes, long lengthBytes) throws Exception {
try (FileInputStream in = new FileInputStream(mFile)) { try (FileInputStream in = new FileInputStream(mFile)) {
Utils.writeToSession(session, in, offsetBytes, lengthBytes); Utils.writeToSession(session, in, offsetBytes, lengthBytes, lengthBytes);
}
}
public void writeToSession(BlobStoreManager.Session session,
long offsetBytes, long lengthBytes, long allocateBytes) throws Exception {
try (FileInputStream in = new FileInputStream(mFile)) {
Utils.writeToSession(session, in, offsetBytes, lengthBytes, allocateBytes);
} }
} }

View File

@@ -59,15 +59,15 @@ public class Utils {
public static void writeToSession(BlobStoreManager.Session session, ParcelFileDescriptor input, public static void writeToSession(BlobStoreManager.Session session, ParcelFileDescriptor input,
long lengthBytes) throws IOException { long lengthBytes) throws IOException {
try (FileInputStream in = new ParcelFileDescriptor.AutoCloseInputStream(input)) { try (FileInputStream in = new ParcelFileDescriptor.AutoCloseInputStream(input)) {
writeToSession(session, in, 0, lengthBytes); writeToSession(session, in, 0, lengthBytes, lengthBytes);
} }
} }
public static void writeToSession(BlobStoreManager.Session session, FileInputStream in, public static void writeToSession(BlobStoreManager.Session session, FileInputStream in,
long offsetBytes, long lengthBytes) throws IOException { long offsetBytes, long lengthBytes, long allocateBytes) throws IOException {
in.getChannel().position(offsetBytes); in.getChannel().position(offsetBytes);
try (FileOutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream( try (FileOutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(
session.openWrite(offsetBytes, lengthBytes))) { session.openWrite(offsetBytes, allocateBytes))) {
copy(in, out, lengthBytes); copy(in, out, lengthBytes);
} }
} }