Clean up full transport logic in ContentProviderBackupComponent
This commit is contained in:
parent
1b44225707
commit
f5e723b1a1
2 changed files with 2 additions and 31 deletions
|
@ -7,9 +7,9 @@ import android.net.Uri;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.stevesoltys.backup.transport.component.BackupComponent;
|
import com.stevesoltys.backup.transport.component.BackupComponent;
|
||||||
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration;
|
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration;
|
||||||
|
import sun.misc.IOUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
|
@ -162,7 +162,6 @@ public class ContentProviderBackupComponent implements BackupComponent {
|
||||||
|
|
||||||
backupState.setInputFileDescriptor(fileDescriptor);
|
backupState.setInputFileDescriptor(fileDescriptor);
|
||||||
backupState.setInputStream(new FileInputStream(fileDescriptor.getFileDescriptor()));
|
backupState.setInputStream(new FileInputStream(fileDescriptor.getFileDescriptor()));
|
||||||
backupState.setBuffer(new byte[INITIAL_BUFFER_SIZE]);
|
|
||||||
backupState.setBytesTransferred(0);
|
backupState.setBytesTransferred(0);
|
||||||
|
|
||||||
ZipEntry zipEntry = new ZipEntry(configuration.getFullBackupDirectory() + backupState.getPackageName());
|
ZipEntry zipEntry = new ZipEntry(configuration.getFullBackupDirectory() + backupState.getPackageName());
|
||||||
|
@ -210,29 +209,11 @@ public class ContentProviderBackupComponent implements BackupComponent {
|
||||||
return TRANSPORT_QUOTA_EXCEEDED;
|
return TRANSPORT_QUOTA_EXCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = backupState.getBuffer();
|
|
||||||
if (numBytes > buffer.length) {
|
|
||||||
buffer = new byte[numBytes];
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream inputStream = backupState.getInputStream();
|
InputStream inputStream = backupState.getInputStream();
|
||||||
ZipOutputStream outputStream = backupState.getOutputStream();
|
ZipOutputStream outputStream = backupState.getOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int bytesRemaining = numBytes;
|
outputStream.write(IOUtils.readFully(inputStream, numBytes, true));
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
backupState.setBytesTransferred(bytesTransferred);
|
backupState.setBytesTransferred(bytesTransferred);
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
|
@ -20,8 +20,6 @@ class ContentProviderBackupState {
|
||||||
|
|
||||||
private long bytesTransferred;
|
private long bytesTransferred;
|
||||||
|
|
||||||
private byte[] buffer;
|
|
||||||
|
|
||||||
private String packageName;
|
private String packageName;
|
||||||
|
|
||||||
private int packageIndex;
|
private int packageIndex;
|
||||||
|
@ -81,12 +79,4 @@ class ContentProviderBackupState {
|
||||||
void setPackageIndex(int packageIndex) {
|
void setPackageIndex(int packageIndex) {
|
||||||
this.packageIndex = packageIndex;
|
this.packageIndex = packageIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] getBuffer() {
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBuffer(byte[] buffer) {
|
|
||||||
this.buffer = buffer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue