always log reason for failed file transfer

This commit is contained in:
Daniel Gultsch 2015-05-14 11:57:51 +02:00
parent 4414cf3b27
commit 8d472157a4
2 changed files with 18 additions and 2 deletions

View file

@ -97,11 +97,13 @@ public class JingleInbandTransport extends JingleTransport {
file.createNewFile(); file.createNewFile();
this.fileOutputStream = file.createOutputStream(); this.fileOutputStream = file.createOutputStream();
if (this.fileOutputStream == null) { if (this.fileOutputStream == null) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not create output stream");
callback.onFileTransferAborted(); callback.onFileTransferAborted();
return; return;
} }
this.remainingSize = this.fileSize = file.getExpectedSize(); this.remainingSize = this.fileSize = file.getExpectedSize();
} catch (final NoSuchAlgorithmException | IOException e) { } catch (final NoSuchAlgorithmException | IOException e) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+" "+e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} }
} }
@ -122,6 +124,7 @@ public class JingleInbandTransport extends JingleTransport {
this.digest.reset(); this.digest.reset();
fileInputStream = this.file.createInputStream(); fileInputStream = this.file.createInputStream();
if (fileInputStream == null) { if (fileInputStream == null) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could no create input stream");
callback.onFileTransferAborted(); callback.onFileTransferAborted();
return; return;
} }
@ -130,6 +133,7 @@ public class JingleInbandTransport extends JingleTransport {
} }
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
callback.onFileTransferAborted(); callback.onFileTransferAborted();
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": "+e.getMessage());
} }
} }
@ -182,7 +186,7 @@ public class JingleInbandTransport extends JingleTransport {
fileInputStream.close(); fileInputStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
Log.d(Config.LOGTAG,e.getMessage()); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": "+e.getMessage());
FileBackend.close(fileInputStream); FileBackend.close(fileInputStream);
this.onFileTransmissionStatusChanged.onFileTransferAborted(); this.onFileTransmissionStatusChanged.onFileTransferAborted();
} }
@ -206,7 +210,7 @@ public class JingleInbandTransport extends JingleTransport {
connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100)); connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));
} }
} catch (IOException e) { } catch (IOException e) {
Log.d(Config.LOGTAG,e.getMessage()); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": "+e.getMessage());
FileBackend.close(fileOutputStream); FileBackend.close(fileOutputStream);
this.onFileTransmissionStatusChanged.onFileTransferAborted(); this.onFileTransmissionStatusChanged.onFileTransferAborted();
} }

View file

@ -1,5 +1,7 @@
package eu.siacs.conversations.xmpp.jingle; package eu.siacs.conversations.xmpp.jingle;
import android.util.Log;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -10,6 +12,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays; import java.util.Arrays;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
@ -102,6 +105,7 @@ public class JingleSocks5Transport extends JingleTransport {
digest.reset(); digest.reset();
fileInputStream = file.createInputStream(); fileInputStream = file.createInputStream();
if (fileInputStream == null) { if (fileInputStream == null) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": could not create input stream");
callback.onFileTransferAborted(); callback.onFileTransferAborted();
return; return;
} }
@ -121,10 +125,13 @@ public class JingleSocks5Transport extends JingleTransport {
callback.onFileTransmitted(file); callback.onFileTransmitted(file);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} catch (IOException e) { } catch (IOException e) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} finally { } finally {
FileBackend.close(fileInputStream); FileBackend.close(fileInputStream);
@ -150,6 +157,7 @@ public class JingleSocks5Transport extends JingleTransport {
fileOutputStream = file.createOutputStream(); fileOutputStream = file.createOutputStream();
if (fileOutputStream == null) { if (fileOutputStream == null) {
callback.onFileTransferAborted(); callback.onFileTransferAborted();
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": could not create output stream");
return; return;
} }
double size = file.getExpectedSize(); double size = file.getExpectedSize();
@ -160,6 +168,7 @@ public class JingleSocks5Transport extends JingleTransport {
count = inputStream.read(buffer); count = inputStream.read(buffer);
if (count == -1) { if (count == -1) {
callback.onFileTransferAborted(); callback.onFileTransferAborted();
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": file ended prematurely with "+remainingSize+" bytes remaining");
return; return;
} else { } else {
fileOutputStream.write(buffer, 0, count); fileOutputStream.write(buffer, 0, count);
@ -173,10 +182,13 @@ public class JingleSocks5Transport extends JingleTransport {
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest())); file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
callback.onFileTransmitted(file); callback.onFileTransmitted(file);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} catch (IOException e) { } catch (IOException e) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} finally { } finally {
FileBackend.close(fileOutputStream); FileBackend.close(fileOutputStream);