You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by br...@apache.org on 2013/09/25 21:18:41 UTC

svn commit: r1526270 - /hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java

Author: brock
Date: Wed Sep 25 19:18:40 2013
New Revision: 1526270

URL: http://svn.apache.org/r1526270
Log:
HIVE-5349 - QTestutil does not properly set UTF-8 (Edward Capriolo via Brock Noland)

Modified:
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java

Modified: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java?rev=1526270&r1=1526269&r2=1526270&view=diff
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java (original)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java Wed Sep 25 19:18:40 2013
@@ -29,9 +29,11 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.io.Serializable;
+import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -46,6 +48,7 @@ import java.util.TreeMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.fs.FileStatus;
@@ -91,6 +94,7 @@ import org.apache.zookeeper.ZooKeeper;
  */
 public class QTestUtil {
 
+  public static final String UTF_8 = "UTF-8";
   private static final Log LOG = LogFactory.getLog("QTestUtil");
 
   private String testWarehouse;
@@ -324,27 +328,26 @@ public class QTestUtil {
     }
   }
 
-  public void addFile(String qFile) throws Exception {
-
-    File qf = new File(qFile);
-    addFile(qf);
+  public String readEntireFileIntoString(File queryFile) throws IOException {
+    InputStreamReader isr = new InputStreamReader(
+        new BufferedInputStream(new FileInputStream(queryFile)), QTestUtil.UTF_8);
+    StringWriter sw = new StringWriter();
+    try {
+      IOUtils.copy(isr, sw);
+    } finally {
+      if (isr != null) {
+        isr.close();
+      }
+    }
+    return sw.toString();
   }
 
-  public void addFile(File qf) throws Exception {
-
-    FileInputStream fis = new FileInputStream(qf);
-    BufferedInputStream bis = new BufferedInputStream(fis);
-    BufferedReader br = new BufferedReader(new InputStreamReader(bis, "UTF8"));
-    StringBuilder qsb = new StringBuilder();
-
-    // Read the entire query
-    String line;
-    while ((line = br.readLine()) != null) {
-      qsb.append(line + "\n");
-    }
-    br.close();
+  public void addFile(String queryFile) throws IOException {
+    addFile(new File(queryFile));
+  }
 
-    String query = qsb.toString();
+  public void addFile(File qf) throws IOException  {
+    String query = readEntireFileIntoString(qf);
     qMap.put(qf.getName(), query);
 
     if(checkHadoopVersionExclude(qf.getName(), query)