|
35 | 35 | import com.crashlytics.android.Crashlytics; |
36 | 36 | import com.dropbox.core.v2.DbxClientV2; |
37 | 37 | import com.dropbox.core.v2.files.FileMetadata; |
38 | | -import com.dropbox.core.v2.files.Metadata; |
39 | 38 | import com.google.android.gms.common.api.GoogleApiClient; |
40 | 39 | import com.google.android.gms.drive.Drive; |
41 | 40 | import com.google.android.gms.drive.DriveApi; |
|
68 | 67 |
|
69 | 68 | import java.io.File; |
70 | 69 | import java.io.FileInputStream; |
71 | | -import java.io.FileOutputStream; |
72 | 70 | import java.io.IOException; |
73 | 71 | import java.io.OutputStream; |
74 | | -import java.nio.channels.FileChannel; |
75 | 72 | import java.text.SimpleDateFormat; |
76 | 73 | import java.util.ArrayList; |
77 | 74 | import java.util.Date; |
@@ -282,7 +279,7 @@ private void moveExportToUri() throws Exporter.ExporterException { |
282 | 279 | try { |
283 | 280 | OutputStream outputStream = mContext.getContentResolver().openOutputStream(exportUri); |
284 | 281 | // Now we always get just one file exported (QIFs are zipped) |
285 | | - moveFile(mExportedFiles.get(0), outputStream); |
| 282 | + org.gnucash.android.util.FileUtils.moveFile(mExportedFiles.get(0), outputStream); |
286 | 283 | } catch (IOException ex) { |
287 | 284 | throw new Exporter.ExporterException(mExportParams, "Error when moving file to URI"); |
288 | 285 | } |
@@ -429,7 +426,7 @@ private List<String> moveExportToSDCard() throws Exporter.ExporterException { |
429 | 426 | for (String src: mExportedFiles) { |
430 | 427 | String dst = Exporter.getExportFolderPath(mExporter.mBookUID) + stripPathPart(src); |
431 | 428 | try { |
432 | | - moveFile(src, dst); |
| 429 | + org.gnucash.android.util.FileUtils.moveFile(src, dst); |
433 | 430 | dstFiles.add(dst); |
434 | 431 | } catch (IOException e) { |
435 | 432 | throw new Exporter.ExporterException(mExportParams, e); |
@@ -521,49 +518,6 @@ private ArrayList<Uri> convertFilePathsToUris(List<String> paths) { |
521 | 518 | return exportFiles; |
522 | 519 | } |
523 | 520 |
|
524 | | - /** |
525 | | - * Moves a file from <code>src</code> to <code>dst</code> |
526 | | - * @param src Absolute path to the source file |
527 | | - * @param dst Absolute path to the destination file |
528 | | - * @throws IOException if the file could not be moved. |
529 | | - */ |
530 | | - public void moveFile(String src, String dst) throws IOException { |
531 | | - File srcFile = new File(src); |
532 | | - File dstFile = new File(dst); |
533 | | - FileChannel inChannel = new FileInputStream(srcFile).getChannel(); |
534 | | - FileChannel outChannel = new FileOutputStream(dstFile).getChannel(); |
535 | | - try { |
536 | | - inChannel.transferTo(0, inChannel.size(), outChannel); |
537 | | - } finally { |
538 | | - if (inChannel != null) |
539 | | - inChannel.close(); |
540 | | - outChannel.close(); |
541 | | - } |
542 | | - srcFile.delete(); |
543 | | - } |
544 | | - |
545 | | - /** |
546 | | - * Move file from a location on disk to an outputstream. |
547 | | - * The outputstream could be for a URI in the Storage Access Framework |
548 | | - * @param src Input file (usually newly exported file) |
549 | | - * @param outputStream Output stream to write to |
550 | | - * @throws IOException if error occurred while moving the file |
551 | | - */ |
552 | | - public void moveFile(@NonNull String src, @NonNull OutputStream outputStream) throws IOException { |
553 | | - byte[] buffer = new byte[1024]; |
554 | | - int read; |
555 | | - try (FileInputStream inputStream = new FileInputStream(src)) { |
556 | | - while ((read = inputStream.read(buffer)) != -1) { |
557 | | - outputStream.write(buffer, 0, read); |
558 | | - } |
559 | | - } finally { |
560 | | - outputStream.flush(); |
561 | | - outputStream.close(); |
562 | | - } |
563 | | - Log.i(TAG, "Deleting temp export file: " + src); |
564 | | - new File(src).delete(); |
565 | | - } |
566 | | - |
567 | 521 | private void reportSuccess() { |
568 | 522 | String targetLocation; |
569 | 523 | switch (mExportParams.getExportTarget()){ |
|
0 commit comments