aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlen Stampoultzis <glens@apache.org>2004-08-10 02:59:52 +0000
committerGlen Stampoultzis <glens@apache.org>2004-08-10 02:59:52 +0000
commit3a59e361ff066a5d3d25fbbf05fab8d848f1f6e0 (patch)
tree342b0e3498e5655baadb6a50d2f70dc271b3a68c
parent7abc766ebbdc4a280ba21b1c76869cd0eaab6a79 (diff)
downloadpoi-3a59e361ff066a5d3d25fbbf05fab8d848f1f6e0.tar.gz
poi-3a59e361ff066a5d3d25fbbf05fab8d848f1f6e0.zip
Empty byte array case for HexDump
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353579 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/util/HexDump.java7
-rw-r--r--src/testcases/org/apache/poi/util/TestHexDump.java5
2 files changed, 12 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/util/HexDump.java b/src/java/org/apache/poi/util/HexDump.java
index 77a49ed041..710797b6b4 100644
--- a/src/java/org/apache/poi/util/HexDump.java
+++ b/src/java/org/apache/poi/util/HexDump.java
@@ -73,6 +73,12 @@ public class HexDump
throws IOException, ArrayIndexOutOfBoundsException,
IllegalArgumentException
{
+ if (data.length == 0)
+ {
+ stream.write( "No Data".getBytes() );
+ stream.flush();
+ return;
+ }
if ((index < 0) || (index >= data.length))
{
throw new ArrayIndexOutOfBoundsException(
@@ -83,6 +89,7 @@ public class HexDump
{
throw new IllegalArgumentException("cannot write to nullstream");
}
+
long display_offset = offset + index;
StringBuffer buffer = new StringBuffer(74);
diff --git a/src/testcases/org/apache/poi/util/TestHexDump.java b/src/testcases/org/apache/poi/util/TestHexDump.java
index 9c9e48607f..6189d3e441 100644
--- a/src/testcases/org/apache/poi/util/TestHexDump.java
+++ b/src/testcases/org/apache/poi/util/TestHexDump.java
@@ -277,6 +277,11 @@ public class TestHexDump
// as expected
}
+
+ // verify proper behaviour with empty byte array
+ ByteArrayOutputStream os = new ByteArrayOutputStream( );
+ HexDump.dump( new byte[0], 0, os, 0 );
+ assertEquals( "No Data", os.toString() );
}
public void testToHex()