Repository: sentry Updated Branches: refs/heads/sentry-ha-redesign 39d7b6166 -> 4ccc15fe7
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/4ccc15fe Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/4ccc15fe Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/4ccc15fe Branch: refs/heads/sentry-ha-redesign Commit: 4ccc15fe7ad91c546b8bee70c2a0ebc4f86114e8 Parents: 39d7b61 Author: Alexander Kolbasov <[email protected]> Authored: Wed May 10 10:26:16 2017 -0700 Committer: Alexander Kolbasov <[email protected]> Committed: Wed May 10 10:26:16 2017 -0700 ---------------------------------------------------------------------- .../src/main/java/org/apache/sentry/SentryMain.java | 10 ++++++---- .../org/apache/sentry/provider/file/PolicyFiles.java | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/4ccc15fe/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/4ccc15fe/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java index f8be739..8f0ffd1 100644 --- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java +++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java @@ -17,11 +17,11 @@ package org.apache.sentry.provider.file; 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(); }
