]> source.dussan.org Git - poi.git/commitdiff
More friendly output of byte arrays for property values in HSMFDump
authorNick Burch <nick@apache.org>
Wed, 26 Jun 2013 16:03:09 +0000 (16:03 +0000)
committerNick Burch <nick@apache.org>
Wed, 26 Jun 2013 16:03:09 +0000 (16:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1496982 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java

index ec20e4e57c750e83bbee94f8d66b8baac772a8f9..25a525ab60b868fb3fe93739451eb5fa07f09d2f 100644 (file)
@@ -62,6 +62,42 @@ public class ByteChunk extends Chunk {
       this.value = value;
    }
    
+   /**
+    * Returns the data in a debug-friendly string format
+    */
+   public String toString() {
+       return toDebugFriendlyString(value);
+   }
+   
+   /**
+    * Formats the byte array in a debug-friendly way,
+    *  showing all of a short array, and the start of a 
+    *  longer one.
+    */
+   protected static String toDebugFriendlyString(byte[] value) {
+      if (value == null)
+         return "(Null Byte Array)";
+          
+      StringBuffer text = new StringBuffer();
+      text.append("Bytes len=").append(value.length);
+      text.append(" [");
+      
+      int limit = Math.min(value.length, 16);
+      if (value.length > 16) {
+          limit = 12;
+      }
+      for (int i=0; i<limit; i++) {
+          if (i > 0)
+              text.append(',');
+          text.append(value[i]);
+      }
+      if (value.length > 16) {
+          text.append(",....");
+      }
+      text.append("]");
+      return text.toString();
+   }
+   
    /**
     * Returns the data, formatted as a string assuming it
     *  was a non-unicode string.
index 1b67ba0243dd96118cbccd05c8473ab96aca1cba..1ea8a2628d9499a9a711923a596d3211e915702d 100644 (file)
@@ -60,7 +60,16 @@ public class PropertyValue {
    }
    
    public String toString() {
-      return property + " = " + getValue();
+      Object v = getValue();
+      if (v == null)
+          return "(No value available)";
+      
+      if (v instanceof byte[]) {
+          return ByteChunk.toDebugFriendlyString((byte[])v);
+      } else {
+          // Just use the normal toString on the value
+          return v.toString();
+      }
    }
    
    // TODO classes for the other important value types