accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [1/5] git commit: Ensure streams are closed and use utf8 encoding.
Date Fri, 31 Jan 2014 18:54:10 GMT
Updated Branches:
  refs/heads/2292-findbugs d1f139eb4 -> 3bc08e9cf


Ensure streams are closed and use utf8 encoding.


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

Branch: refs/heads/2292-findbugs
Commit: 0d38c5c3b6c0ef244635d0997543bd04505c8046
Parents: d1f139e
Author: Josh Elser <elserj@apache.org>
Authored: Fri Jan 31 12:35:54 2014 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Fri Jan 31 12:35:54 2014 -0500

----------------------------------------------------------------------
 .../util/shell/commands/HistoryCommand.java     | 33 +++++++++++++-------
 1 file changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d38c5c3/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
index 6de8c39..43dc64f 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
@@ -17,12 +17,16 @@
 package org.apache.accumulo.core.util.shell.commands;
 
 import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 
+import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
 import org.apache.commons.cli.CommandLine;
@@ -43,22 +47,25 @@ public class HistoryCommand extends Command {
     int counter = 0;
     
     if (cl.hasOption(clearHist.getOpt())) {
-      
+      PrintWriter out = null;
       try {
-        
-        final FileWriter outFile = new FileWriter(histDir + "/shell_history.txt");
-        final PrintWriter out = new PrintWriter(outFile);
-        out.close();
-        
-      } catch (IOException e) {
-        
+        FileOutputStream file = new FileOutputStream(histDir + "/shell_history.txt");
+        final BufferedWriter fileWriter = new BufferedWriter(new OutputStreamWriter(file,
Constants.UTF8));
+        out = new PrintWriter(fileWriter);
+      } catch (FileNotFoundException e) { 
         e.printStackTrace();
+      } finally {
+        // If the file existed, closing the 
+        if (null != out) {
+          out.close();
+        }
       }
     }
     
     else {
+      BufferedReader in = null;
       try {
-        final BufferedReader in = new BufferedReader(new FileReader(histDir + "/shell_history.txt"));
+        in = new BufferedReader(new InputStreamReader(new FileInputStream(histDir + "/shell_history.txt"),
Constants.UTF8));
         String Line;
         try {
           Line = in.readLine();
@@ -74,6 +81,10 @@ public class HistoryCommand extends Command {
       } catch (FileNotFoundException e) {
         
         e.printStackTrace();
+      } finally {
+        if (null != in) {
+          in.close();
+        }
       }
     }
     


Mime
View raw message