You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2019/04/24 21:58:53 UTC

[accumulo] branch master updated: Fix #1087, wrap FileWriter with BufferedWriter (#1088)

This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new ebb3a2b  Fix #1087, wrap FileWriter with BufferedWriter (#1088)
ebb3a2b is described below

commit ebb3a2b2ed148cd8d14070eb46ec39fb986222a4
Author: bd2019us <47...@users.noreply.github.com>
AuthorDate: Wed Apr 24 16:58:49 2019 -0500

    Fix #1087, wrap FileWriter with BufferedWriter (#1088)
---
 .../org/apache/accumulo/server/util/Admin.java     | 98 +++++++++++-----------
 1 file changed, 49 insertions(+), 49 deletions(-)

diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
index f1180a2..9540284 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.server.util;
 
 import static java.util.Objects.requireNonNull;
 
+import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -506,23 +507,23 @@ public class Admin implements KeywordExecutable {
       File outputDirectory)
       throws IOException, AccumuloException, AccumuloSecurityException, NamespaceNotFoundException {
     File namespaceScript = new File(outputDirectory, namespace + NS_FILE_SUFFIX);
-    FileWriter nsWriter = new FileWriter(namespaceScript);
-    nsWriter.write(createNsFormat.format(new String[] {namespace}));
-    TreeMap<String,String> props = new TreeMap<>();
-    for (Entry<String,String> p : accumuloClient.namespaceOperations().getProperties(namespace)) {
-      props.put(p.getKey(), p.getValue());
-    }
-    for (Entry<String,String> entry : props.entrySet()) {
-      String defaultValue = getDefaultConfigValue(entry.getKey());
-      if (defaultValue == null || !defaultValue.equals(entry.getValue())) {
-        if (!entry.getValue().equals(siteConfig.get(entry.getKey()))
-            && !entry.getValue().equals(systemConfig.get(entry.getKey()))) {
-          nsWriter.write(nsConfigFormat
-              .format(new String[] {namespace, entry.getKey() + "=" + entry.getValue()}));
+    try (BufferedWriter nsWriter = new BufferedWriter(new FileWriter(namespaceScript))) {
+      nsWriter.write(createNsFormat.format(new String[] {namespace}));
+      TreeMap<String,String> props = new TreeMap<>();
+      for (Entry<String,String> p : accumuloClient.namespaceOperations().getProperties(namespace)) {
+        props.put(p.getKey(), p.getValue());
+      }
+      for (Entry<String,String> entry : props.entrySet()) {
+        String defaultValue = getDefaultConfigValue(entry.getKey());
+        if (defaultValue == null || !defaultValue.equals(entry.getValue())) {
+          if (!entry.getValue().equals(siteConfig.get(entry.getKey()))
+              && !entry.getValue().equals(systemConfig.get(entry.getKey()))) {
+            nsWriter.write(nsConfigFormat
+                .format(new String[] {namespace, entry.getKey() + "=" + entry.getValue()}));
+          }
         }
       }
     }
-    nsWriter.close();
   }
 
   @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
@@ -530,31 +531,30 @@ public class Admin implements KeywordExecutable {
   private static void printUserConfiguration(AccumuloClient accumuloClient, String user,
       File outputDirectory) throws IOException, AccumuloException, AccumuloSecurityException {
     File userScript = new File(outputDirectory, user + USER_FILE_SUFFIX);
-    FileWriter userWriter = new FileWriter(userScript);
-    userWriter.write(createUserFormat.format(new String[] {user}));
-    Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(user);
-    userWriter.write(userAuthsFormat.format(new String[] {user, auths.toString()}));
-    for (SystemPermission sp : SystemPermission.values()) {
-      if (accumuloClient.securityOperations().hasSystemPermission(user, sp)) {
-        userWriter.write(sysPermFormat.format(new String[] {sp.name(), user}));
+    try (BufferedWriter userWriter = new BufferedWriter(new FileWriter(userScript))) {
+      userWriter.write(createUserFormat.format(new String[] {user}));
+      Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(user);
+      userWriter.write(userAuthsFormat.format(new String[] {user, auths.toString()}));
+      for (SystemPermission sp : SystemPermission.values()) {
+        if (accumuloClient.securityOperations().hasSystemPermission(user, sp)) {
+          userWriter.write(sysPermFormat.format(new String[] {sp.name(), user}));
+        }
       }
-    }
-    for (String namespace : accumuloClient.namespaceOperations().list()) {
-      for (NamespacePermission np : NamespacePermission.values()) {
-        if (accumuloClient.securityOperations().hasNamespacePermission(user, namespace, np)) {
-          userWriter.write(nsPermFormat.format(new String[] {np.name(), namespace, user}));
+      for (String namespace : accumuloClient.namespaceOperations().list()) {
+        for (NamespacePermission np : NamespacePermission.values()) {
+          if (accumuloClient.securityOperations().hasNamespacePermission(user, namespace, np)) {
+            userWriter.write(nsPermFormat.format(new String[] {np.name(), namespace, user}));
+          }
         }
       }
-    }
-    for (String tableName : accumuloClient.tableOperations().list()) {
-      for (TablePermission perm : TablePermission.values()) {
-        if (accumuloClient.securityOperations().hasTablePermission(user, tableName, perm)) {
-          userWriter.write(tablePermFormat.format(new String[] {perm.name(), tableName, user}));
+      for (String tableName : accumuloClient.tableOperations().list()) {
+        for (TablePermission perm : TablePermission.values()) {
+          if (accumuloClient.securityOperations().hasTablePermission(user, tableName, perm)) {
+            userWriter.write(tablePermFormat.format(new String[] {perm.name(), tableName, user}));
+          }
         }
       }
     }
-
-    userWriter.close();
   }
 
   private void printSystemConfiguration(File outputDirectory) throws IOException {
@@ -574,7 +574,7 @@ public class Admin implements KeywordExecutable {
       }
     }
     File siteBackup = new File(outputDirectory, ACCUMULO_SITE_BACKUP_FILE);
-    try (FileWriter fw = new FileWriter(siteBackup)) {
+    try (BufferedWriter fw = new BufferedWriter(new FileWriter(siteBackup))) {
       for (Entry<String,String> prop : conf.entrySet()) {
         fw.write(prop.getKey() + "=" + prop.getValue() + "\n");
       }
@@ -586,24 +586,24 @@ public class Admin implements KeywordExecutable {
   private void printTableConfiguration(AccumuloClient accumuloClient, String tableName,
       File outputDirectory) throws AccumuloException, TableNotFoundException, IOException {
     File tableBackup = new File(outputDirectory, tableName + ".cfg");
-    FileWriter writer = new FileWriter(tableBackup);
-    writer.write(createTableFormat.format(new String[] {tableName}));
-    TreeMap<String,String> props = new TreeMap<>();
-    for (Entry<String,String> p : accumuloClient.tableOperations().getProperties(tableName)) {
-      props.put(p.getKey(), p.getValue());
-    }
-    for (Entry<String,String> prop : props.entrySet()) {
-      if (prop.getKey().startsWith(Property.TABLE_PREFIX.getKey())) {
-        String defaultValue = getDefaultConfigValue(prop.getKey());
-        if (defaultValue == null || !defaultValue.equals(prop.getValue())) {
-          if (!prop.getValue().equals(siteConfig.get(prop.getKey()))
-              && !prop.getValue().equals(systemConfig.get(prop.getKey()))) {
-            writer.write(configFormat
-                .format(new String[] {tableName, prop.getKey() + "=" + prop.getValue()}));
+    try (BufferedWriter writer = new BufferedWriter(new FileWriter(tableBackup))) {
+      writer.write(createTableFormat.format(new String[] {tableName}));
+      TreeMap<String,String> props = new TreeMap<>();
+      for (Entry<String,String> p : accumuloClient.tableOperations().getProperties(tableName)) {
+        props.put(p.getKey(), p.getValue());
+      }
+      for (Entry<String,String> prop : props.entrySet()) {
+        if (prop.getKey().startsWith(Property.TABLE_PREFIX.getKey())) {
+          String defaultValue = getDefaultConfigValue(prop.getKey());
+          if (defaultValue == null || !defaultValue.equals(prop.getValue())) {
+            if (!prop.getValue().equals(siteConfig.get(prop.getKey()))
+                && !prop.getValue().equals(systemConfig.get(prop.getKey()))) {
+              writer.write(configFormat
+                  .format(new String[] {tableName, prop.getKey() + "=" + prop.getValue()}));
+            }
           }
         }
       }
     }
-    writer.close();
   }
 }