aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-03 19:59:11 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-03 19:59:11 +0100
commitec9c264cf757f0dd78991f72ebf54164bad12995 (patch)
treec97a0f6f512402d9f9cfa289214aededad7bac4d /src/main/java
parent21069003b05b984cfe67f9f6f8479c97a803e3da (diff)
more error handling for http connection
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpConnection.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpConnection.java b/src/main/java/eu/siacs/conversations/http/HttpConnection.java
index 0810e167..24eb5ed3 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpConnection.java
@@ -1,5 +1,11 @@
package eu.siacs.conversations.http;
+import android.content.Intent;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+
+import org.apache.http.conn.ssl.StrictHostnameVerifier;
+
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -15,12 +21,6 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.X509TrustManager;
-import org.apache.http.conn.ssl.StrictHostnameVerifier;
-
-import android.content.Intent;
-import android.graphics.BitmapFactory;
-import android.net.Uri;
-
import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
@@ -74,7 +74,7 @@ public class HttpConnection implements Downloadable {
if (reference != null && reference.length() == 96) {
this.file.setKey(CryptoHelper.hexToBytes(reference));
}
-
+
if (this.message.getEncryption() == Message.ENCRYPTION_OTR
&& this.file.getKey() == null) {
this.message.setEncryption(Message.ENCRYPTION_NONE);
@@ -113,7 +113,7 @@ public class HttpConnection implements Downloadable {
}
private void setupTrustManager(HttpsURLConnection connection,
- boolean interactive) {
+ boolean interactive) {
X509TrustManager trustManager;
HostnameVerifier hostnameVerifier;
if (interactive) {
@@ -131,7 +131,7 @@ public class HttpConnection implements Downloadable {
}
try {
SSLContext sc = SSLContext.getInstance("TLS");
- sc.init(null, new X509TrustManager[] { trustManager },
+ sc.init(null, new X509TrustManager[]{trustManager},
mXmppConnectionService.getRNG());
connection.setSSLSocketFactory(sc.getSocketFactory());
connection.setHostnameVerifier(hostnameVerifier);
@@ -230,6 +230,9 @@ public class HttpConnection implements Downloadable {
BufferedInputStream is = new BufferedInputStream(
connection.getInputStream());
OutputStream os = file.createOutputStream();
+ if (os == null) {
+ throw new IOException();
+ }
int count = -1;
byte[] buffer = new byte[1024];
while ((count = is.read(buffer)) != -1) {