]> source.dussan.org Git - poi.git/commitdiff
Fixed a small problem with hex dump
authorGlen Stampoultzis <glens@apache.org>
Sun, 13 Jul 2003 13:51:53 +0000 (13:51 +0000)
committerGlen Stampoultzis <glens@apache.org>
Sun, 13 Jul 2003 13:51:53 +0000 (13:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353209 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/HexDump.java
src/testcases/org/apache/poi/util/TestHexDump.java

index d45b239bf765f7c2d06011174161be28ac33d7f5..74198bc525b00c1ca141e2768991557841a6b266 100644 (file)
@@ -109,12 +109,14 @@ public class HexDump
             throws IOException, ArrayIndexOutOfBoundsException,
                     IllegalArgumentException
     {
-        if ((index < 0) || (index >= data.length))
+        if ((index < 0) || (data.length != 0 && index >= data.length))
         {
             throw new ArrayIndexOutOfBoundsException(
                 "illegal index: " + index + " into array of length "
                 + data.length);
         }
+        if (data.length == 0)
+            return; // nothing more to do.
         if (stream == null)
         {
             throw new IllegalArgumentException("cannot write to nullstream");
index 7a86cff76413f12845af3d00ca758bc594848bc6..c8e3ca9e5c88bd615a6838f4e52e512e34d66879 100644 (file)
@@ -314,6 +314,9 @@ public class TestHexDump
 
             // as expected
         }
+
+        // verify proper behaviour with a 0 length dump on 0 length dataset
+        HexDump.dump(new byte[0], 0, new ByteArrayOutputStream(), 0, 0);
     }
 
     public void testToHex()