public static String toByteArray(byte[] buf,int ofs,int len){
  StringBuffer sb=new StringBuffer();
  for (int i=ofs; (i < len) && (i < buf.length); i++) {
    sb.append('0');
    sb.append('x');
    sb.append(hexchars[(buf[i] & 0xF0) >> 4]);
    sb.append(hexchars[buf[i] & 0x0F]);
    if (((i + 1) < len) && ((i + 1) < buf.length)) {
      sb.append(',');
    }
  }
  return sb.toString();
}

public static String toByteArray ( byte [ ] buf , int ofs , int len ) { StringBuffer sb = new StringBuffer ( ) ; for ( int i = ofs ; ( i < len ) && ( i < buf . length ) ; i ++ ) { sb . append ( '0' ) ; sb . append ( 'x' ) ; sb . append ( hexchars [ ( buf [ i ] & 0xF0 ) > > 4 ] ) ; sb . append ( hexchars [ buf [ i ] & 0x0F ] ) ; if ( ( ( i + 1 ) < len ) && ( ( i + 1 ) < buf . length ) ) { sb . append ( ',' ) ; } } return sb . toString ( ) ; }
returns a string which can be written to a java source file as part of a static initializer for a byte array . returns data in the format 0xab , 0xcd , . . . . use like : javafile . print ( " byte [ ] data = { " ) javafile . print ( hexdump . tobytearray ( data ) ) ; javafile . println ( " } ; " ) ;
