public static String dumpString ( byte [ ] b ) { StringBuilder d = new StringBuilder ( b . length * 2 ) ; for ( byte aB : b ) { char c = ( char ) aB ; if ( Character . isISOControl ( c ) ) { switch ( c ) { case ' ' : d . append ( "{CR}" ) ; break ; case ' ' : d . append ( "{LF}" ) ; break ; case ' ' : d . append ( "{NULL}" ) ; break ; default : char hi = Character . forDigit ( ( aB >> 4 ) & 0x0F , 16 ) ; char lo = Character . forDigit ( aB & 0x0F , 16 ) ; d . append ( ' ' ) . append ( Character . toUpperCase ( hi ) ) . append ( Character . toUpperCase ( lo ) ) . append ( ' ' ) ; break ; } } else d . append ( c ) ; } return d . toString ( ) ; }
converts a byte array to printable characters