diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-14 14:04:34 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-15 15:34:12 +0100 |
commit | af2922adeac1b5dd6e4f30e930ad54171b5511a9 (patch) | |
tree | 15dcc4b58d67ff552d87fe523eb9af6ca3929fda /src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java | |
parent | e7a70a46e0154740177dcdea7fad255dcd4067e9 (diff) |
progress for ibb transfers
Diffstat (limited to 'src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java | 22 |
1 files changed, 16 insertions, 6 deletions
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 e3f4fd619..791f48600 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java @@ -8,6 +8,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; import android.util.Base64; + import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.utils.CryptoHelper; @@ -28,10 +29,12 @@ public class JingleInbandTransport extends JingleTransport { private boolean established = false; private DownloadableFile file; + private JingleConnection connection; private InputStream fileInputStream = null; private OutputStream fileOutputStream; - private long remainingSize; + private long remainingSize = 0; + private long fileSize = 0; private MessageDigest digest; private OnFileTransmissionStatusChanged onFileTransmissionStatusChanged; @@ -45,10 +48,10 @@ public class JingleInbandTransport extends JingleTransport { } }; - public JingleInbandTransport(final Account account, final Jid counterpart, - final String sid, final int blocksize) { - this.account = account; - this.counterpart = counterpart; + public JingleInbandTransport(final JingleConnection connection, final String sid, final int blocksize) { + this.connection = connection; + this.account = connection.getAccount(); + this.counterpart = connection.getCounterPart(); this.blockSize = blocksize; this.bufferSize = blocksize / 4; this.sessionId = sid; @@ -92,7 +95,7 @@ public class JingleInbandTransport extends JingleTransport { callback.onFileTransferAborted(); return; } - this.remainingSize = file.getExpectedSize(); + this.remainingSize = this.fileSize = file.getExpectedSize(); } catch (final NoSuchAlgorithmException | IOException e) { callback.onFileTransferAborted(); } @@ -104,6 +107,8 @@ public class JingleInbandTransport extends JingleTransport { this.onFileTransmissionStatusChanged = callback; this.file = file; try { + this.remainingSize = this.file.getSize(); + this.fileSize = this.remainingSize; this.digest = MessageDigest.getInstance("SHA-1"); this.digest.reset(); fileInputStream = this.file.createInputStream(); @@ -126,6 +131,7 @@ public class JingleInbandTransport extends JingleTransport { fileInputStream.close(); this.onFileTransmissionStatusChanged.onFileTransmitted(file); } else { + this.remainingSize -= count; this.digest.update(buffer); String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP); IqPacket iq = new IqPacket(IqPacket.TYPE_SET); @@ -140,6 +146,7 @@ public class JingleInbandTransport extends JingleTransport { this.account.getXmppConnection().sendIqPacket(iq, this.onAckReceived); this.seq++; + connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100)); } } catch (IOException e) { this.onFileTransmissionStatusChanged.onFileTransferAborted(); @@ -155,6 +162,7 @@ public class JingleInbandTransport extends JingleTransport { } this.remainingSize -= buffer.length; + this.fileOutputStream.write(buffer); this.digest.update(buffer); @@ -163,6 +171,8 @@ public class JingleInbandTransport extends JingleTransport { fileOutputStream.flush(); fileOutputStream.close(); this.onFileTransmissionStatusChanged.onFileTransmitted(file); + } else { + connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100)); } } catch (IOException e) { this.onFileTransmissionStatusChanged.onFileTransferAborted(); |