You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/10/05 02:27:48 UTC

svn commit: r1706741 - in /poi/trunk/src: examples/src/org/apache/poi/poifs/poibrowser/ java/org/apache/poi/util/

Author: kiwiwings
Date: Mon Oct  5 00:27:47 2015
New Revision: 1706741

URL: http://svn.apache.org/viewvc?rev=1706741&view=rev
Log:
obsoleted Codec classes by HexDump

Removed:
    poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/Codec.java
Modified:
    poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptorRenderer.java
    poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java
    poi/trunk/src/java/org/apache/poi/util/HexDump.java

Modified: poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptorRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptorRenderer.java?rev=1706741&r1=1706740&r2=1706741&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptorRenderer.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/DocumentDescriptorRenderer.java Mon Oct  5 00:27:47 2015
@@ -21,6 +21,8 @@ import java.awt.*;
 import javax.swing.*;
 import javax.swing.tree.*;
 
+import org.apache.poi.util.HexDump;
+
 /**
  * <p>{@link TreeCellRenderer} for a {@link DocumentDescriptor}. The
  * renderer is extremly rudimentary since displays only the document's
@@ -34,11 +36,11 @@ public class DocumentDescriptorRenderer
 
     public Component getTreeCellRendererComponent(final JTree tree,
                                                   final Object value,
-                                                  final boolean selected,
+                                                  final boolean selectedCell,
                                                   final boolean expanded,
                                                   final boolean leaf,
                                                   final int row,
-                                                  final boolean hasFocus)
+                                                  final boolean hasCellFocus)
     {
         final DocumentDescriptor d = (DocumentDescriptor)
             ((DefaultMutableTreeNode) value).getUserObject();
@@ -47,8 +49,9 @@ public class DocumentDescriptorRenderer
         text.append(renderAsString(d));
         text.setFont(new Font("Monospaced", Font.PLAIN, 10));
         p.add(text);
-        if (selected)
+        if (selectedCell) {
             Util.invert(text);
+        }
         return p;
     }
 
@@ -58,19 +61,19 @@ public class DocumentDescriptorRenderer
      */
     protected String renderAsString(final DocumentDescriptor d)
     {
-        final StringBuffer b = new StringBuffer();
+        final StringBuilder b = new StringBuilder();
         b.append("Name: ");
         b.append(d.name);
-        b.append(" (");
-        b.append(Codec.hexEncode(d.name));
-        b.append(")  \n");
+        b.append(" ");
+        b.append(HexDump.toHex(d.name));
+        b.append("\n");
 
         b.append("Size: ");
         b.append(d.size);
         b.append(" bytes\n");
 
         b.append("First bytes: ");
-        b.append(Codec.hexEncode(d.bytes));
+        b.append(HexDump.toHex(d.bytes));
 
         return b.toString();
     }

Modified: poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java?rev=1706741&r1=1706740&r2=1706741&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java Mon Oct  5 00:27:47 2015
@@ -32,6 +32,7 @@ import org.apache.poi.hpsf.Property;
 import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.Section;
 import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.util.HexDump;
 
 /**
  * <p>Renders a {@link PropertySetDescriptor} by more or less dumping
@@ -59,14 +60,14 @@ public class PropertySetDescriptorRender
         text.setBackground(new Color(200, 255, 200));
         text.setFont(new Font("Monospaced", Font.PLAIN, 10));
         text.append(renderAsString(d));
-        text.append("\nByte order: " +
-                    Codec.hexEncode((short) ps.getByteOrder()));
-        text.append("\nFormat: " +
-                    Codec.hexEncode((short) ps.getFormat()));
-        text.append("\nOS version: " +
-                    Codec.hexEncode(ps.getOSVersion()));
-        text.append("\nClass ID: " +
-                    Codec.hexEncode(ps.getClassID()));
+        text.append("\nByte order: ");
+        text.append(HexDump.toHex((short) ps.getByteOrder()));
+        text.append("\nFormat: ");
+        text.append(HexDump.toHex((short) ps.getFormat()));
+        text.append("\nOS version: ");
+        text.append(HexDump.toHex(ps.getOSVersion()));
+        text.append("\nClass ID: ");
+        text.append(HexDump.toHex(ps.getClassID().getBytes()));
         text.append("\nSection count: " + ps.getSectionCount());
         text.append(sectionsToString(ps.getSections()));
         p.add(text);
@@ -132,7 +133,7 @@ public class PropertySetDescriptorRender
     {
         final StringBuffer b = new StringBuffer();
         b.append("\n" + name + " Format ID: ");
-        b.append(Codec.hexEncode(s.getFormatID()));
+        b.append(HexDump.toHex(s.getFormatID().getBytes()));
         b.append("\n" + name + " Offset: " + s.getOffset());
         b.append("\n" + name + " Section size: " + s.getSize());
         b.append("\n" + name + " Property count: " + s.getPropertyCount());
@@ -153,17 +154,17 @@ public class PropertySetDescriptorRender
             b.append("), Type: ");
             b.append(type);
             b.append(", Value: ");
-            if (value instanceof byte[])
-            {
-                byte[] b2 = (byte[]) value;
-                b.append("0x" + Codec.hexEncode(b2, 0, 4));
+            if (value instanceof byte[]) {
+                byte[] buf = new byte[4];
+                System.arraycopy(value, 0, buf, 0, 4);
+                b.append(HexDump.toHex(buf));
                 b.append(' ');
-                b.append("0x" + Codec.hexEncode(b2, 4, b2.length - 4));
-            }
-            else if (value != null)
+                System.arraycopy(value, ((byte[])value).length - 4, buf, 0, 4);
+            } else if (value != null) {
                 b.append(value.toString());
-            else
+            } else {
                 b.append("null");
+            }
         }
         return b.toString();
     }

Modified: poi/trunk/src/java/org/apache/poi/util/HexDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/HexDump.java?rev=1706741&r1=1706740&r2=1706741&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/HexDump.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/HexDump.java Mon Oct  5 00:27:47 2015
@@ -172,7 +172,8 @@ public class HexDump {
         if (Character.isISOControl(charB)) return '.';
         
         switch (charB) {
-        case 0xFF: case 0xDD: // printable, but not compilable with current compiler encoding
+        // printable, but not compilable with current compiler encoding
+        case 0xFF: case 0xDD:
             charB = '.';
             break;
         }
@@ -187,7 +188,7 @@ public class HexDump {
      */
     public static String toHex(final byte[] value)
     {
-        StringBuffer retVal = new StringBuffer();
+        StringBuilder retVal = new StringBuilder();
         retVal.append('[');
         if (value != null && value.length > 0)
         {
@@ -211,7 +212,7 @@ public class HexDump {
      */
     public static String toHex(final short[] value)
     {
-        StringBuffer retVal = new StringBuffer();
+        StringBuilder retVal = new StringBuilder();
         retVal.append('[');
         for(int x = 0; x < value.length; x++)
         {
@@ -261,7 +262,7 @@ public class HexDump {
      * @param value     The value to convert
      * @return          The result right padded with 0
      */
-    public static String toHex(final short value) {
+    public static String toHex(short value) {
         return xpad(value & 0xFFFF, 4, "");
     }
 
@@ -271,7 +272,7 @@ public class HexDump {
      * @param value     The value to convert
      * @return          The result right padded with 0
      */
-    public static String toHex(final byte value) {
+    public static String toHex(byte value) {
         return xpad(value & 0xFF, 2, "");
     }
 
@@ -281,7 +282,7 @@ public class HexDump {
      * @param value     The value to convert
      * @return          The result right padded with 0
      */
-    public static String toHex(final int value) {
+    public static String toHex(int value) {
         return xpad(value & 0xFFFFFFFF, 8, "");
     }
 
@@ -291,11 +292,23 @@ public class HexDump {
      * @param value     The value to convert
      * @return          The result right padded with 0
      */
-    public static String toHex(final long value) {
-        return xpad(value & 0xFFFFFFFF, 16, "");
+    public static String toHex(long value) {
+        return xpad(value, 16, "");
     }
 
     /**
+     * Converts the string to a string of hex values.
+     *
+     * @param value     The value to convert
+     * @return          The resulted hex string
+     */
+    public static String toHex(String value) {
+        return (value == null || value.length() == 0)
+            ? "[]"
+            : toHex(value.getBytes(LocaleUtil.CHARSET_1252));
+    }
+    
+    /**
      * Dumps <code>bytesToDump</code> bytes to an output stream.
      *
      * @param in          The stream to read from



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