code: public static final String hexdump(byte[] buffer, int offset, int length, boolean ascii, int columns, String prefix)
     {
        StringBuilder sb = new StringBuilder();
        if (buffer != null)
        {
           int index = offset;
           DecimalFormat df = new DecimalFormat("00000");
  
           while (index < (offset + length))
           {
              if (index + columns > (offset + length))
              {
                 columns = (offset + length) - index;
              }
  
              sb.append(prefix);
              sb.append(df.format(index - offset));
              sb.append(":");
              sb.append(hexdump(buffer, index, columns, ascii));
              sb.append('\n');
  
              index += columns;
           }
        }
  
        return (sb.toString());
     }
docs: Dump raw data as hex.
  
  @param buffer buffer
  @param offset offset into buffer
  @param length length of data to dump
  @param ascii true if ASCII should also be printed
  @param columns number of columns
  @param prefix prefix when printing
  @return hex dump