### Question:
HexPrinter { public static String hex( ByteBuffer bytes, int offset, int length ) { return hex( bytes, offset, length, DEFAULT_BYTES_PER_GROUP, DEFAULT_GROUP_SEPARATOR ); } HexPrinter( PrintStream out );  HexPrinter( PrintStream out, int bytesPerGroup, String groupSep ); HexPrinter withBytesPerLine( int bytesPerLine ); HexPrinter withBytesPerGroup( int bytesPerGroup ); HexPrinter withGroupSeparator( String separator ); HexPrinter withLineNumberDigits( int maxLineNumberDigits ); HexPrinter withLineNumberPrefix( String prefix ); HexPrinter withLineNumberSuffix( String suffix ); HexPrinter withLineNumberOffset( long offset ); HexPrinter withByteSeparator( String byteSeparator ); HexPrinter withBytesGroupingFormat( int bytesPerLine, int bytesPerGroup, String separator ); HexPrinter withLineNumberFormat( int maxLineNumberDigits, String prefix, String suffix ); HexPrinter append( byte value ); HexPrinter append( ReadableByteChannel source ); HexPrinter append( ReadableByteChannel source, int atMost ); HexPrinter append( ByteBuffer bytes, int offset, int length ); HexPrinter append( ByteBuffer bytes ); HexPrinter append( byte[] bytes ); static String hex( ByteBuffer bytes, int offset, int length ); static String hex( ByteBuffer bytes, int offset, int length, int bytesPerBlock, String groupSep ); static String hex( ByteBuffer bytes ); static String hex( ByteBuffer bytes, int bytesPerBlock, String groupSep  ); static String hex( byte[] bytes ); static String hex( byte[] bytes, int bytesPerBlock, String groupSep ); static String hex( byte b );  }### Answer:
@Test public void shouldPrintPartOfByteBuffer() { ByteBuffer bytes = ByteBuffer.allocate( 1024 ); for ( byte value = 0; value < 33; value++ ) { bytes.put( value ); } String hexString = HexPrinter.hex( bytes, 3, 8 ); assertEquals( format( "03 04 05 06 07 08 09 0A" ), hexString ); }
@Test public void shouldOnlyPrintBytesWrittenToBuffer() { ByteBuffer bytes = ByteBuffer.allocate( 1024 ); for ( byte value = 0; value < 10; value++ ) { bytes.put( value ); } bytes.flip(); String hexString = HexPrinter.hex( bytes ); assertEquals( format( "00 01 02 03 04 05 06 07 08 09" ), hexString ); }