android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java | 24 +++++++--- 1 file changed, 18 insertions(+), 6 deletions(-)
New commits: commit da9897f72575a502711cbb7b84fc7817cb31c2bd Author: Jan Holesovsky <ke...@collabora.com> AuthorDate: Mon Mar 16 18:35:43 2020 +0100 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Mon Mar 16 19:42:06 2020 +0100 android: Use "wt" mode even for Export As. And use a real tempfile for that when I'm touching this code. Change-Id: Iad6ea41b9e9c6459f66f1dee0258092ead1b8de5 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90587 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Michael Meeks <michael.me...@collabora.com> diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java index 434b467ce..c1edd099a 100644 --- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java +++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java @@ -613,20 +613,32 @@ public class LOActivity extends AppCompatActivity { } String format = getFormatForRequestCode(requestCode); if (format != null) { - final File tempFile = new File(LOActivity.this.getCacheDir(), "temp.file"); - LOActivity.this.saveAs(tempFile.toURI().toString(), format); - try (InputStream inputStream = new FileInputStream(tempFile)) { - OutputStream outputStream = getContentResolver().openOutputStream(intent.getData()); + InputStream inputStream = null; + OutputStream outputStream = null; + try { + final File tempFile = File.createTempFile("LibreOffice", "." + format, this.getCacheDir()); + LOActivity.this.saveAs(tempFile.toURI().toString(), format); + + inputStream = new FileInputStream(tempFile); + outputStream = getContentResolver().openOutputStream(intent.getData(), "wt"); + byte[] buffer = new byte[4096]; int len; - while ((len = inputStream.read(buffer)) > 0) { + while ((len = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, len); } outputStream.flush(); - outputStream.close(); } catch (Exception e) { Toast.makeText(this, "Something went wrong while Saving as: " + e.getMessage(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); + } finally { + try { + if (inputStream != null) + inputStream.close(); + if (outputStream != null) + outputStream.close(); + } catch (Exception e) { + } } return; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits