Empty byte array case for HexDump

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353579 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Glen Stampoultzis 2004-08-10 02:59:52 +00:00
parent 5c4a6f5ce9
commit 7bfd22842b
2 changed files with 12 additions and 0 deletions

View File

@ -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);

View File

@ -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()