poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1496982 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes: ByteChunk.java PropertyValue.java
Date Wed, 26 Jun 2013 16:03:09 GMT
Author: nick
Date: Wed Jun 26 16:03:09 2013
New Revision: 1496982

URL: http://svn.apache.org/r1496982
Log:
More friendly output of byte arrays for property values in HSMFDump

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

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java?rev=1496982&r1=1496981&r2=1496982&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java Wed Jun 26 16:03:09
2013
@@ -63,6 +63,42 @@ public class ByteChunk extends Chunk {
    }
    
    /**
+    * 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.
     * If your data isn't in fact stored as basically

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java?rev=1496982&r1=1496981&r2=1496982&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertyValue.java Wed Jun
26 16:03:09 2013
@@ -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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message