public static String dump ( final int displayOffset , final byte [ ] data , final int offset , final int len ) { StringBuilder sb = new StringBuilder ( ) ; Formatter formatter = new Formatter ( sb ) ; StringBuilder ascii = new StringBuilder ( ) ; int dataNdx = offset ; final int maxDataNdx = offset + len ; final int lines = ( len + 16 ) / 16 ; for ( int i = 0 ; i < lines ; i ++ ) { ascii . append ( " |" ) ; formatter . format ( "%08x " , displayOffset + ( i * 16 ) ) ; for ( int j = 0 ; j < 16 ; j ++ ) { if ( dataNdx < maxDataNdx ) { byte b = data [ dataNdx ++ ] ; formatter . format ( "%02x " , b ) ; ascii . append ( ( b > MIN_VISIBLE && b < MAX_VISIBLE ) ? ( char ) b : ' ' ) ; } else { sb . append ( " " ) ; } if ( j == 7 ) { sb . append ( ' ' ) ; } } ascii . append ( ' ' ) ; sb . append ( ascii ) . append ( ' ' ) ; ascii . setLength ( 0 ) ; } formatter . close ( ) ; return sb . toString ( ) ; }
Dump an array of bytes in hexadecimal .