From f5e723b1a1d25bc181e92cda1cf46332d7f76611 Mon Sep 17 00:00:00 2001 From: Steve Soltys Date: Tue, 17 Oct 2017 23:33:17 -0400 Subject: [PATCH] Clean up full transport logic in ContentProviderBackupComponent --- .../ContentProviderBackupComponent.java | 23 ++----------------- .../backup/ContentProviderBackupState.java | 10 -------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupComponent.java b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupComponent.java index 18bf8938..9d26d7bc 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupComponent.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupComponent.java @@ -7,9 +7,9 @@ import android.net.Uri; import android.os.ParcelFileDescriptor; import android.util.Base64; import android.util.Log; - import com.stevesoltys.backup.transport.component.BackupComponent; import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration; +import sun.misc.IOUtils; import java.io.*; import java.security.InvalidAlgorithmParameterException; @@ -162,7 +162,6 @@ public class ContentProviderBackupComponent implements BackupComponent { backupState.setInputFileDescriptor(fileDescriptor); backupState.setInputStream(new FileInputStream(fileDescriptor.getFileDescriptor())); - backupState.setBuffer(new byte[INITIAL_BUFFER_SIZE]); backupState.setBytesTransferred(0); ZipEntry zipEntry = new ZipEntry(configuration.getFullBackupDirectory() + backupState.getPackageName()); @@ -210,29 +209,11 @@ public class ContentProviderBackupComponent implements BackupComponent { return TRANSPORT_QUOTA_EXCEEDED; } - byte[] buffer = backupState.getBuffer(); - if (numBytes > buffer.length) { - buffer = new byte[numBytes]; - } - InputStream inputStream = backupState.getInputStream(); ZipOutputStream outputStream = backupState.getOutputStream(); try { - int bytesRemaining = numBytes; - - while (bytesRemaining > 0) { - int bytesRead = inputStream.read(buffer, 0, bytesRemaining); - - if (bytesRead < 0) { - Log.e(TAG, "Unexpected EOD; failing backup"); - return TRANSPORT_ERROR; - } - - outputStream.write(buffer, 0, bytesRead); - bytesRemaining -= bytesRead; - } - + outputStream.write(IOUtils.readFully(inputStream, numBytes, true)); backupState.setBytesTransferred(bytesTransferred); } catch (IOException ex) { diff --git a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupState.java b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupState.java index 87cddabc..3a7f8ed8 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupState.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/backup/ContentProviderBackupState.java @@ -20,8 +20,6 @@ class ContentProviderBackupState { private long bytesTransferred; - private byte[] buffer; - private String packageName; private int packageIndex; @@ -81,12 +79,4 @@ class ContentProviderBackupState { void setPackageIndex(int packageIndex) { this.packageIndex = packageIndex; } - - byte[] getBuffer() { - return buffer; - } - - void setBuffer(byte[] buffer) { - this.buffer = buffer; - } }