From 396ad3361f41a11d06164be56f31f660dc6a43be Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 26 Oct 2017 18:42:10 +0200 Subject: [PATCH] Jingle: create output stream on demand --- .../conversations/xmpp/jingle/JingleConnection.java | 11 +++++++++-- .../xmpp/jingle/JingleInbandTransport.java | 2 -- .../xmpp/jingle/JingleSocks5Transport.java | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 73638ffbe..c91c7ac61 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -5,6 +5,7 @@ import android.util.Log; import android.util.Pair; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; @@ -154,7 +155,14 @@ public class JingleConnection implements Transferable { return this.mFileInputStream; } - public OutputStream getFileOutputStream() { + public OutputStream getFileOutputStream() throws IOException { + if (this.file == null) { + Log.d(Config.LOGTAG,"file object was not assigned"); + return null; + } + this.file.getParentFile().mkdirs(); + this.file.createNewFile(); + this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file,message.getEncryption() == Message.ENCRYPTION_AXOLOTL); return this.mFileOutputStream; } @@ -459,7 +467,6 @@ public class JingleConnection implements Transferable { this.file.setKeyAndIv(key); } } - this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file,message.getEncryption() == Message.ENCRYPTION_AXOLOTL); this.file.setExpectedSize(size); message.resetFileParams(); Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize()); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java index 43e605138..b78b20ff7 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java @@ -101,8 +101,6 @@ public class JingleInbandTransport extends JingleTransport { try { this.digest = MessageDigest.getInstance("SHA-1"); digest.reset(); - file.getParentFile().mkdirs(); - file.createNewFile(); this.fileOutputStream = connection.getFileOutputStream(); if (this.fileOutputStream == null) { Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not create output stream"); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java index 463e640ac..a6159c0c9 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java @@ -141,8 +141,6 @@ public class JingleSocks5Transport extends JingleTransport { digest.reset(); //inputStream.skip(45); socket.setSoTimeout(30000); - file.getParentFile().mkdirs(); - file.createNewFile(); fileOutputStream = connection.getFileOutputStream(); if (fileOutputStream == null) { callback.onFileTransferAborted();