diff options
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/jingle')
-rw-r--r-- | src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java | 2 | ||||
-rw-r--r-- | src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java | 34 |
2 files changed, 20 insertions, 16 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 01f7e9ca..90d81b50 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -94,7 +94,7 @@ public class JingleConnection { mXmppConnectionService.databaseBackend.createMessage(message); mXmppConnectionService.markMessage(message, Message.STATUS_RECIEVED); } - Log.d("xmppService","sucessfully transmitted file:"+file.getName()+" encryption:"+message.getEncryption()); + Log.d("xmppService","sucessfully transmitted file:"+file.getAbsolutePath()); } }; diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java index a46e4a47..7ecc5edf 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java @@ -1,11 +1,12 @@ package eu.siacs.conversations.xmpp.jingle; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import android.util.Base64; import eu.siacs.conversations.entities.Account; @@ -26,14 +27,14 @@ public class JingleInbandTransport extends JingleTransport { private boolean established = false; private JingleFile file; - - private FileInputStream fileInputStream = null; - private FileOutputStream fileOutputStream; + + private InputStream fileInputStream = null; + private OutputStream fileOutputStream; private long remainingSize; private MessageDigest digest; - - private OnFileTransmitted onFileTransmitted; + private OnFileTransmitted onFileTransmitted; + private OnIqPacketReceived onAckReceived = new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { @@ -84,7 +85,7 @@ public class JingleInbandTransport extends JingleTransport { digest.reset(); file.getParentFile().mkdirs(); file.createNewFile(); - this.fileOutputStream = new FileOutputStream(file); + this.fileOutputStream = getOutputStream(file); this.remainingSize = file.getExpectedSize(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); @@ -100,7 +101,7 @@ public class JingleInbandTransport extends JingleTransport { try { this.digest = MessageDigest.getInstance("SHA-1"); this.digest.reset(); - fileInputStream = new FileInputStream(file); + fileInputStream = this.getInputStream(file); this.sendNextBlock(); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -113,17 +114,17 @@ public class JingleInbandTransport extends JingleTransport { byte[] buffer = new byte[this.bufferSize]; try { int count = fileInputStream.read(buffer); - if (count==-1) { + if (count == -1) { file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest())); fileInputStream.close(); this.onFileTransmitted.onFileTransmitted(file); } else { this.digest.update(buffer); - String base64 = Base64.encodeToString(buffer, Base64.DEFAULT); + String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP); IqPacket iq = new IqPacket(IqPacket.TYPE_SET); iq.setTo(this.counterpart); - Element data = iq - .addChild("data", "http://jabber.org/protocol/ibb"); + Element data = iq.addChild("data", + "http://jabber.org/protocol/ibb"); data.setAttribute("seq", "" + this.seq); data.setAttribute("block-size", "" + this.blockSize); data.setAttribute("sid", this.sessionId); @@ -140,7 +141,10 @@ public class JingleInbandTransport extends JingleTransport { private void receiveNextBlock(String data) { try { - byte[] buffer = Base64.decode(data, Base64.DEFAULT); + byte[] buffer = Base64.decode(data, Base64.NO_WRAP); + if (this.remainingSize < buffer.length) { + buffer = Arrays.copyOfRange(buffer, 0, (int) this.remainingSize); + } this.remainingSize -= buffer.length; this.fileOutputStream.write(buffer); @@ -172,7 +176,7 @@ public class JingleInbandTransport extends JingleTransport { this.account.getXmppConnection().sendIqPacket( packet.generateRespone(IqPacket.TYPE_RESULT), null); } else { - //TODO some sort of exception + // TODO some sort of exception } } } |