Author: jbellis Date: Tue Sep 27 05:33:06 2011 New Revision: 1176204 URL: http://svn.apache.org/viewvc?rev=1176204&view=rev Log: fix formatting, use closeQuietly
Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/security/SSLFactory.java Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/security/SSLFactory.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/security/SSLFactory.java?rev=1176204&r1=1176203&r2=1176204&view=diff ============================================================================== --- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/security/SSLFactory.java (original) +++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/security/SSLFactory.java Tue Sep 27 05:33:06 2011 @@ -25,7 +25,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.security.KeyStore; import javax.net.ssl.KeyManagerFactory; @@ -35,6 +34,7 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.TrustManagerFactory; import org.apache.cassandra.config.EncryptionOptions; +import org.apache.cassandra.io.util.FileUtils; /** * A Factory for providing and setting up Client and Server SSL wrapped @@ -46,7 +46,6 @@ public final class SSLFactory private static final String ALGORITHM = "SunX509"; private static final String STORE_TYPE = "JKS"; - public static SSLServerSocket getServerSocket(EncryptionOptions options, InetAddress address, int port) throws IOException { SSLContext ctx = createSSLContext(options); @@ -75,14 +74,16 @@ public final class SSLFactory return socket; } - private static SSLContext createSSLContext(EncryptionOptions options) throws IOException { + private static SSLContext createSSLContext(EncryptionOptions options) throws IOException + { FileInputStream tsf = new FileInputStream(options.truststore); FileInputStream ksf = new FileInputStream(options.keystore); SSLContext ctx; - try { + try + { ctx = SSLContext.getInstance(PROTOCOL); - TrustManagerFactory tmf = null; - KeyManagerFactory kmf = null; + TrustManagerFactory tmf; + KeyManagerFactory kmf; tmf = TrustManagerFactory.getInstance(ALGORITHM); KeyStore ts = KeyStore.getInstance(STORE_TYPE); @@ -96,11 +97,15 @@ public final class SSLFactory ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); - } catch (Exception e) { + } + catch (Exception e) + { throw new IOException("Error creating the initializing the SSL Context", e); - } finally { - tsf.close(); - ksf.close(); + } + finally + { + FileUtils.closeQuietly(tsf); + FileUtils.closeQuietly(ksf); } return ctx; }