Jingle: create output stream on demand

This commit is contained in:
Daniel Gultsch 2017-10-26 18:42:10 +02:00
parent 73db0bd19f
commit 396ad3361f
3 changed files with 9 additions and 6 deletions

View file

@ -5,6 +5,7 @@ import android.util.Log;
import android.util.Pair; import android.util.Pair;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -154,7 +155,14 @@ public class JingleConnection implements Transferable {
return this.mFileInputStream; 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; return this.mFileOutputStream;
} }
@ -459,7 +467,6 @@ public class JingleConnection implements Transferable {
this.file.setKeyAndIv(key); this.file.setKeyAndIv(key);
} }
} }
this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file,message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
this.file.setExpectedSize(size); this.file.setExpectedSize(size);
message.resetFileParams(); message.resetFileParams();
Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize()); Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());

View file

@ -101,8 +101,6 @@ public class JingleInbandTransport extends JingleTransport {
try { try {
this.digest = MessageDigest.getInstance("SHA-1"); this.digest = MessageDigest.getInstance("SHA-1");
digest.reset(); digest.reset();
file.getParentFile().mkdirs();
file.createNewFile();
this.fileOutputStream = connection.getFileOutputStream(); this.fileOutputStream = connection.getFileOutputStream();
if (this.fileOutputStream == null) { if (this.fileOutputStream == null) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not create output stream"); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not create output stream");

View file

@ -141,8 +141,6 @@ public class JingleSocks5Transport extends JingleTransport {
digest.reset(); digest.reset();
//inputStream.skip(45); //inputStream.skip(45);
socket.setSoTimeout(30000); socket.setSoTimeout(30000);
file.getParentFile().mkdirs();
file.createNewFile();
fileOutputStream = connection.getFileOutputStream(); fileOutputStream = connection.getFileOutputStream();
if (fileOutputStream == null) { if (fileOutputStream == null) {
callback.onFileTransferAborted(); callback.onFileTransferAborted();