directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [4/4] directory-kerby git commit: Removed FileOutputStream
Date Wed, 26 Apr 2017 10:36:10 GMT
Removed FileOutputStream


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/b7da10e3
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/b7da10e3
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/b7da10e3

Branch: refs/heads/trunk
Commit: b7da10e3815a8ab84ab7ff4fa3572c92bfa9aef5
Parents: f0d593f
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Apr 26 11:35:56 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Apr 26 11:35:56 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/kerby/config/Resource.java   |  7 +++----
 .../src/main/java/org/apache/kerby/util/Util.java         |  4 ++--
 .../kerb/integration/test/jaas/TokenAuthLoginModule.java  | 10 +++++-----
 .../kerberos/kerb/integration/test/jaas/TokenCache.java   |  4 ++--
 .../org/apache/kerby/kerberos/kerb/common/Krb5Parser.java |  6 +++---
 .../kerberos/kerb/preauth/pkinit/CertificateHelper.java   |  8 ++++----
 .../kerby/kerberos/kerb/crypto/random/NativeRandom.java   |  6 ++----
 .../kerberos/kerb/server/preauth/token/TokenPreauth.java  |  8 ++++----
 .../org/apache/kerby/kerberos/tool/klist/KlistTool.java   |  5 +++--
 .../org/apache/kerby/kerberos/tool/token/TokenCache.java  |  7 +++----
 10 files changed, 31 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
----------------------------------------------------------------------
diff --git a/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
b/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
index d0cd70c..ffe6e8d 100644
--- a/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
+++ b/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
@@ -20,10 +20,9 @@
 package org.apache.kerby.config;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.Map;
 import java.util.Properties;
 
@@ -87,9 +86,9 @@ public final class Resource {
         return new Resource("propConfig", propertiesConfig, Format.PROPERTIES);
     }
 
-    private Resource(String name, File resourceFile, Format format) throws FileNotFoundException
{
+    private Resource(String name, File resourceFile, Format format) throws IOException {
         this.name = name;
-        this.resource = new FileInputStream(resourceFile);
+        this.resource = Files.newInputStream(resourceFile.toPath());
         this.format = format;
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/Util.java
----------------------------------------------------------------------
diff --git a/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/Util.java b/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/Util.java
index f8c779e..d247030 100644
--- a/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/Util.java
+++ b/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/Util.java
@@ -33,13 +33,13 @@ package org.apache.kerby.util;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.security.cert.Certificate;
@@ -190,7 +190,7 @@ public class Util {
     }
 
     public static byte[] fileToBytes(final File f) throws IOException {
-        return streamToBytes(new FileInputStream(f));
+        return streamToBytes(Files.newInputStream(f.toPath()));
     }
 
     public static byte[] streamToBytes(final ByteArrayInputStream in,

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenAuthLoginModule.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenAuthLoginModule.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenAuthLoginModule.java
index 3732402..cc45991 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenAuthLoginModule.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenAuthLoginModule.java
@@ -48,9 +48,9 @@ import javax.security.auth.kerberos.KerberosTicket;
 import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.InputStream;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.security.Principal;
 import java.security.PrivateKey;
 import java.security.interfaces.RSAPrivateKey;
@@ -276,9 +276,9 @@ public class TokenAuthLoginModule implements LoginModule {
                 if (tokenEncoder instanceof JwtTokenEncoder) {
                     PrivateKey signKey = null;
                     try {
-                        FileInputStream fis = new FileInputStream(signKeyFile);
-                        signKey = PrivateKeyReader.loadPrivateKey(fis);
-                    } catch (FileNotFoundException e) {
+                        InputStream is = Files.newInputStream(signKeyFile.toPath());
+                        signKey = PrivateKeyReader.loadPrivateKey(is);
+                    } catch (IOException e) {
                         e.printStackTrace();
                     } catch (Exception e) {
                         e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
index e398407..90cb5cf 100644
--- a/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
+++ b/kerby-kerb/integration-test/src/main/java/org/apache/kerby/kerberos/kerb/integration/test/jaas/TokenCache.java
@@ -25,11 +25,11 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Writer;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 
 /**
  * This class provides APIs for converting token cache file with token string.
@@ -62,7 +62,7 @@ public class TokenCache {
         String token = null;
         try {
             BufferedReader reader = new BufferedReader(
-                    new InputStreamReader(new FileInputStream(cacheFile), StandardCharsets.UTF_8));
+                    new InputStreamReader(Files.newInputStream(cacheFile.toPath()), StandardCharsets.UTF_8));
             String line = reader.readLine();
             reader.close();
             if (line != null) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/Krb5Parser.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/Krb5Parser.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/Krb5Parser.java
index 2a72add..0f2d4cd 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/Krb5Parser.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/Krb5Parser.java
@@ -21,10 +21,10 @@ package org.apache.kerby.kerberos.kerb.common;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.IdentityHashMap;
 import java.util.Iterator;
@@ -55,7 +55,7 @@ public class Krb5Parser {
      * @throws IOException e
      */
     public void load() throws IOException {
-        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(krb5conf),
+        BufferedReader br = new BufferedReader(new InputStreamReader(Files.newInputStream(krb5conf.toPath()),
                 StandardCharsets.UTF_8));
         items = new IdentityHashMap<>();
 
@@ -264,4 +264,4 @@ public class Krb5Parser {
             }
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
index 6ea6feb..379c620 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
@@ -24,9 +24,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.io.IOException;
+import java.nio.file.Files;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
@@ -43,8 +43,8 @@ public class CertificateHelper {
         InputStream res = null;
         if (file.isFile()) {
             try {
-                res = new FileInputStream(file);
-            } catch (FileNotFoundException e) {
+                res = Files.newInputStream(file.toPath());
+            } catch (IOException e) {
                 LOG.error("Can't load cert, file not found. " + e);
             }
         } else {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
index b57bc8c..2b3da83 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
@@ -20,8 +20,6 @@
 package org.apache.kerby.kerberos.kerb.crypto.random;
 
 
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -38,8 +36,8 @@ public class NativeRandom implements RandomProvider {
     @Override
     public void init() {
         try {
-            input = new FileInputStream(randFile);
-        } catch (FileNotFoundException e) {
+            input = Files.newInputStream(Paths.get(randFile));
+        } catch (IOException e) {
             e.printStackTrace();
         }
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
index b39439e..aefee74 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
@@ -45,10 +45,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 import java.util.List;
@@ -153,7 +153,7 @@ public class TokenPreauth extends AbstractPreauthPlugin {
         }
     }
 
-    private InputStream getKeyFileStream(String path, String issuer) throws FileNotFoundException
{
+    private InputStream getKeyFileStream(String path, String issuer) throws IOException {
         File file = new File(path);
         if (file.isDirectory()) {
             File[] listOfFiles = file.listFiles();
@@ -171,9 +171,9 @@ public class TokenPreauth extends AbstractPreauthPlugin {
             if (verifyKeyFile == null) {
                 throw new FileNotFoundException("No key found that matches the issuer name");
             }
-            return new FileInputStream(verifyKeyFile);
+            return Files.newInputStream(verifyKeyFile.toPath());
         } else if (file.isFile()) {
-            return new FileInputStream(file);
+            return Files.newInputStream(file.toPath());
         }
         
         // Not a directory or a file...maybe it's a resource on the classpath

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
index f8b1eca..612b1b8 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
@@ -32,9 +32,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -92,7 +93,7 @@ public class KlistTool {
         } else {
             fileName = klOptions.getStringOption(KlistOption.CREDENTIALS_CACHE);
             try {
-                cis = new FileInputStream(fileName);
+                cis = Files.newInputStream(Paths.get(fileName));
                 cc.load(cis);
             } catch (IOException e) {
                 System.err.println("Failed to open CredentialCache from file: " + fileName);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b7da10e3/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
index 1420063..64b9acd 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
@@ -27,12 +27,11 @@ import org.slf4j.LoggerFactory;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Writer;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 
 public class TokenCache {
     private static final Logger LOG = LoggerFactory.getLogger(TokenCache.class);
@@ -58,8 +57,8 @@ public class TokenCache {
         BufferedReader reader = null;
         try {
             reader = new BufferedReader(
-                new InputStreamReader(new FileInputStream(cacheFile), StandardCharsets.UTF_8));
-        } catch (FileNotFoundException e) {
+                new InputStreamReader(Files.newInputStream(cacheFile.toPath()), StandardCharsets.UTF_8));
+        } catch (IOException e) {
             LOG.error("Can't find the cache file. " + e);
         }
         String line = null;


Mime
View raw message