Revision a09587c7
| F-Droid/src/org/fdroid/fdroid/Utils.java | ||
|---|---|---|
| 48 | 48 | import java.io.BufferedInputStream; | 
| 49 | 49 | import java.io.Closeable; | 
| 50 | 50 | import java.io.File; | 
| 51 | import java.io.FileDescriptor; | |
| 51 | 52 | import java.io.FileInputStream; | 
| 52 | 53 | import java.io.FileOutputStream; | 
| 53 | 54 | import java.io.IOException; | 
| ... | ... | |
| 162 | 163 | } | 
| 163 | 164 |  | 
| 164 | 165 |     public static boolean copy(File inFile, File outFile) {
 | 
| 166 | InputStream input = null; | |
| 167 | OutputStream output = null; | |
| 165 | 168 |         try {
 | 
| 166 |             InputStream input = new FileInputStream(inFile);
 | |
| 167 |             OutputStream output = new FileOutputStream(outFile);
 | |
| 169 |             input  = new FileInputStream(inFile);
 | |
| 170 | output = new FileOutputStream(outFile); | |
| 168 | 171 | Utils.copy(input, output); | 
| 169 | output.close(); | |
| 170 | input.close(); | |
| 171 | 172 | return true; | 
| 172 | 173 |         } catch (IOException e) {
 | 
| 173 | 174 | Log.e(TAG, "I/O error when copying a file", e); | 
| 174 | 175 | return false; | 
| 176 |         } finally {
 | |
| 177 | closeQuietly(output); | |
| 178 | closeQuietly(input); | |
| 175 | 179 | } | 
| 176 | 180 | } | 
| 177 | 181 |  | 
| F-Droid/src/org/fdroid/fdroid/net/AsyncDownloaderFromAndroid.java | ||
|---|---|---|
| 10 | 10 | import android.net.Uri; | 
| 11 | 11 | import android.os.Build; | 
| 12 | 12 | import android.os.ParcelFileDescriptor; | 
| 13 | import android.text.TextUtils; | |
| 14 | import android.util.Log; | |
| 15 |  | |
| 16 | import org.fdroid.fdroid.Utils; | |
| 13 | 17 |  | 
| 14 | 18 | import java.io.File; | 
| 15 | 19 | import java.io.FileDescriptor; | 
| ... | ... | |
| 49 | 53 | this.listener = listener; | 
| 50 | 54 | this.localFile = localFile; | 
| 51 | 55 |  | 
| 52 |         if (downloadTitle == null || downloadTitle.trim().length() == 0) {
 | |
| 56 |         if (TextUtils.isEmpty(downloadTitle)) {
 | |
| 53 | 57 | this.downloadTitle = remoteAddress; | 
| 54 | 58 | } | 
| 55 | 59 |  | 
| ... | ... | |
| 97 | 101 | * @throws IOException | 
| 98 | 102 | */ | 
| 99 | 103 |     private void copyFile(FileDescriptor inputFile, File outputFile) throws IOException {
 | 
| 100 | InputStream is = new FileInputStream(inputFile); | |
| 101 | OutputStream os = new FileOutputStream(outputFile); | |
| 102 | byte[] buffer = new byte[1024]; | |
| 103 | int count = 0; | |
| 104 |  | |
| 104 | InputStream input = null; | |
| 105 | OutputStream output = null; | |
| 105 | 106 |         try {
 | 
| 106 |             while ((count = is.read(buffer, 0, buffer.length)) > 0) {
 | |
| 107 |                 os.write(buffer, 0, count);
 | |
| 108 |             }
 | |
| 107 |             input  = new FileInputStream(inputFile);
 | |
| 108 |             output = new FileOutputStream(outputFile);
 | |
| 109 |             Utils.copy(input, output);
 | |
| 109 | 110 |         } finally {
 | 
| 110 |             os.close();
 | |
| 111 |             is.close();
 | |
| 111 |             Utils.closeQuietly(output);
 | |
| 112 |             Utils.closeQuietly(input);
 | |
| 112 | 113 | } | 
| 113 | 114 | } | 
| 114 | 115 |  | 
Also available in: Unified diff