1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 09:52:16 -05:00

Merge pull request #91 from andrewgaul/findbugs-stream-close

Improve the way we open/close streams.
This commit is contained in:
Andrew Chen 2011-11-03 06:40:07 -07:00
commit 7f046e5f0a
2 changed files with 27 additions and 19 deletions

View File

@ -6,6 +6,7 @@ import android.content.Context;
import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.helper.DomainNameChecker;
import org.apache.commons.io.IOUtils;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
@ -105,12 +106,12 @@ public final class TrustManagerFactory {
}
static {
java.io.InputStream fis = null;
try {
javax.net.ssl.TrustManagerFactory tmf = javax.net.ssl.TrustManagerFactory.getInstance("X509");
Application app = K9.app;
keyStoreFile = new File(app.getDir("KeyStore", Context.MODE_PRIVATE) + File.separator + "KeyStore.bks");
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
java.io.FileInputStream fis;
try {
fis = new java.io.FileInputStream(keyStoreFile);
} catch (FileNotFoundException e1) {
@ -118,9 +119,6 @@ public final class TrustManagerFactory {
}
try {
keyStore.load(fis, "".toCharArray());
//if (fis != null) {
// fis.close();
//}
} catch (IOException e) {
Log.e(LOG_TAG, "KeyStore IOException while initializing TrustManagerFactory ", e);
keyStore = null;
@ -154,6 +152,8 @@ public final class TrustManagerFactory {
Log.e(LOG_TAG, "Unable to get X509 Trust Manager ", e);
} catch (KeyStoreException e) {
Log.e(LOG_TAG, "Key Store exception while initializing TrustManagerFactory ", e);
} finally {
IOUtils.closeQuietly(fis);
}
unsecureTrustManager = new SimpleX509TrustManager();
}
@ -195,17 +195,18 @@ public final class TrustManagerFactory {
}
}
}
java.io.FileOutputStream keyStoreStream;
java.io.OutputStream keyStoreStream = null;
try {
keyStoreStream = new java.io.FileOutputStream(keyStoreFile);
keyStore.store(keyStoreStream, "".toCharArray());
keyStoreStream.close();
} catch (FileNotFoundException e) {
throw new CertificateException("Unable to write KeyStore: " + e.getMessage());
} catch (CertificateException e) {
throw new CertificateException("Unable to write KeyStore: " + e.getMessage());
} catch (IOException e) {
throw new CertificateException("Unable to write KeyStore: " + e.getMessage());
} finally {
IOUtils.closeQuietly(keyStoreStream);
}
} catch (NoSuchAlgorithmException e) {

View File

@ -11,6 +11,7 @@ import com.fsck.k9.mail.Folder.OpenMode;
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mail.transport.TrustedSocketFactory;
import org.apache.commons.io.IOUtils;
import org.apache.http.*;
import org.apache.http.client.CookieStore;
import org.apache.http.client.entity.UrlEncodedFormEntity;
@ -1481,9 +1482,10 @@ public class WebDavStore extends Store {
StringBuilder buffer = new StringBuilder();
String tempText = "";
String resultText = "";
BufferedReader reader;
BufferedReader reader = null;
int currentLines = 0;
try {
istream = WebDavHttpClient.getUngzippedContent(entity);
if (lines != -1) {
@ -1501,6 +1503,11 @@ public class WebDavStore extends Store {
}
wdMessage.parse(istream);
} finally {
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(istream);
}
}
} catch (IllegalArgumentException iae) {