sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject sentry git commit: SENTRY-1730 - Remove FileInputStream/FileOutputStream - Reviewed by Na Li
Date Wed, 03 May 2017 15:51:55 GMT
Repository: sentry
Updated Branches:
  refs/heads/master c625dfe94 -> d128f8396


SENTRY-1730 - Remove FileInputStream/FileOutputStream
 - Reviewed by Na Li


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

Branch: refs/heads/master
Commit: d128f8396a04e84454eb8661e7659a7b1c58a1f5
Parents: c625dfe
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed May 3 16:49:40 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed May 3 16:49:40 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/sentry/SentryMain.java      | 10 ++++++----
 .../org/apache/sentry/core/common/utils/PolicyFiles.java | 11 ++++++-----
 2 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/d128f839/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
index c1518ba..3a981b2 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
@@ -27,7 +27,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableMap;
-import java.io.FileInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Properties;
 
 public class SentryMain {
@@ -68,9 +70,9 @@ public class SentryMain {
       Properties log4jProperties = new Properties();
 
       // Firstly load log properties from properties file
-      FileInputStream istream = new FileInputStream(log4jconf);
-      log4jProperties.load(istream);
-      istream.close();
+      try (InputStream istream = Files.newInputStream(Paths.get(log4jconf))) {
+          log4jProperties.load(istream);
+      }
 
       // Set the log level of DataNucleus.Query to INFO only if it is not set in the
       // properties file

http://git-wip-us.apache.org/repos/asf/sentry/blob/d128f839/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PolicyFiles.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PolicyFiles.java
b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PolicyFiles.java
index 4a632bc..ca2de7a 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PolicyFiles.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PolicyFiles.java
@@ -17,11 +17,11 @@
 package org.apache.sentry.core.common.utils;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
 
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileSystem;
@@ -42,7 +42,9 @@ public final class PolicyFiles {
       throws FileNotFoundException, IOException {
     for(String resource : resources) {
       LOGGER.debug("Copying " + resource + " to " + dest);
-      Resources.copy(Resources.getResource(resource), new FileOutputStream(new File(dest,
resource)));
+      try (OutputStream output = Files.newOutputStream(new File(dest, resource).toPath()))
{
+        Resources.copy(Resources.getResource(resource), output);
+      }
     }
   }
 
@@ -61,10 +63,9 @@ public final class PolicyFiles {
 
   public static void copyFilesToDir(FileSystem fs, Path dest, File inputFile)
       throws IOException {
-    try (InputStream input = new FileInputStream(inputFile.getPath());
+    try (InputStream input = Files.newInputStream(inputFile.toPath());
       FSDataOutputStream out = fs.create(new Path(dest, inputFile.getName()))) {
       ByteStreams.copy(input, out);
-      input.close();
       out.hflush();
       out.close();
     }


Mime
View raw message