incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/8] git commit: Adding a to string binary for chars that cannot be displayed in ascii.
Date Sun, 29 Jun 2014 18:25:24 GMT
Adding a to string binary for chars that cannot be displayed in ascii.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/8596c9d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/8596c9d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/8596c9d8

Branch: refs/heads/apache-blur-0.2
Commit: 8596c9d810214d19eb6cb3ff6c344ef8aa189251
Parents: 4e5199d
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sun Jun 29 13:59:17 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sun Jun 29 13:59:17 2014 -0400

----------------------------------------------------------------------
 .../java/org/apache/blur/utils/BlurUtil.java    | 27 ++++++++++++++++++++
 .../org/apache/blur/shell/QueryCommand.java     | 25 ++++++++++--------
 2 files changed, 42 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8596c9d8/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
index ed4ab0c..f4f63df 100644
--- a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
+++ b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
@@ -30,6 +30,7 @@ import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
 import java.lang.management.ManagementFactory;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
@@ -143,6 +144,8 @@ import com.yammer.metrics.core.MetricName;
 
 public class BlurUtil {
 
+  private static final String UTF_8 = "UTF-8";
+
   public final static SortFieldComparator SORT_FIELD_COMPARATOR = new SortFieldComparator();
 
   private static final Log REQUEST_LOG = LogFactory.getLog("REQUEST_LOG");
@@ -1370,4 +1373,28 @@ public class BlurUtil {
     return buf;
   }
 
+  public static String toStringBinary(final byte[] b, int off, int len) {
+    StringBuilder result = new StringBuilder();
+    String str = toString(b, off, len);
+    for (int i = 0; i < str.length(); ++i) {
+      int ch = str.charAt(i) & 0xFF;
+      if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z')
|| (ch >= 'a' && ch <= 'z')
+          || " `~!@#$%^&*()-_=+[]{}\\|;:'\",.<>/? ".indexOf(ch) >= 0) {
+        result.append(str.charAt(i));
+      } else {
+        result.append(String.format("\\x%02X", ch));
+      }
+    }
+    return result.toString();
+
+  }
+
+  public static String toString(byte[] b, int off, int len) {
+    try {
+      return new String(b, off, len, UTF_8);
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8596c9d8/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
index 699f66a..be5367f 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
@@ -310,10 +310,10 @@ public class QueryCommand extends Command implements TableFirstArgCommand
{
       columnsLabels.add(name);
       tableDisplay.setHeader(indexOf + 3, highlight(getTruncatedVersion(name)));
     }
-    tableDisplay.set(0, line, white(getTruncatedVersion(Integer.toString(result))));
-    tableDisplay.set(1, line, white(getTruncatedVersion(rowId)));
-    tableDisplay.set(2, line, white(getTruncatedVersion(recordId)));
-    tableDisplay.set(indexOf + 3, line, white(getTruncatedVersion(column.getValue())));
+    tableDisplay.set(0, line, white(getTruncatedVersion(toStringBinary(Integer.toString(result)))));
+    tableDisplay.set(1, line, white(getTruncatedVersion(toStringBinary(rowId))));
+    tableDisplay.set(2, line, white(getTruncatedVersion(toStringBinary(recordId))));
+    tableDisplay.set(indexOf + 3, line, white(getTruncatedVersion(toStringBinary(column.getValue()))));
   }
 
   private String getTruncatedVersion(String s) {
@@ -336,7 +336,7 @@ public class QueryCommand extends Command implements TableFirstArgCommand
{
       if (rowResult != null) {
         Row row = rowResult.getRow();
         String id = row.getId();
-        tableDisplay.set(1, line.get(), white(getTruncatedVersion(id)));
+        tableDisplay.set(1, line.get(), white(getTruncatedVersion(toStringBinary(id))));
         List<Record> records = order(row.getRecords());
         String currentFamily = "#";
         for (Record record : records) {
@@ -354,6 +354,11 @@ public class QueryCommand extends Command implements TableFirstArgCommand
{
     }
   }
 
+  private String toStringBinary(String id) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
   private String displayRecordInRowMultiFamilyView(int result, final TableDisplay tableDisplay,
       final AtomicInteger line, final Map<String, List<String>> columnOrder,
final String currentFamily,
       final Record record) {
@@ -363,19 +368,19 @@ public class QueryCommand extends Command implements TableFirstArgCommand
{
     if (!family.equals(currentFamily)) {
       List<String> list = columnOrder.get(family);
       for (int i = 0; i < list.size(); i++) {
-        tableDisplay.set(i + c, line.get(), highlight(getTruncatedVersion(family + "." +
list.get(i))));
+        tableDisplay.set(i + c, line.get(), highlight(getTruncatedVersion(toStringBinary(family
+ "." + list.get(i)))));
       }
-      tableDisplay.set(0, line.get(), white(Integer.toString(result)));
+      tableDisplay.set(0, line.get(), white(toStringBinary(Integer.toString(result))));
       line.incrementAndGet();
     }
-    tableDisplay.set(2, line.get(), white(getTruncatedVersion(record.getRecordId())));
+    tableDisplay.set(2, line.get(), white(getTruncatedVersion(toStringBinary(record.getRecordId()))));
     for (String oc : orderedColumns) {
       if (oc != null) {
-        tableDisplay.set(c, line.get(), white(getTruncatedVersion(oc)));
+        tableDisplay.set(c, line.get(), white(getTruncatedVersion(toStringBinary(oc))));
       }
       c++;
     }
-    tableDisplay.set(0, line.get(), white(Integer.toString(result)));
+    tableDisplay.set(0, line.get(), white(toStringBinary(Integer.toString(result))));
     line.incrementAndGet();
     return family;
   }


Mime
View raw message