code: private static long hexdump(InputStream is, PrintWriter pw) throws Exception
     {
        byte[] buffer = new byte[BUFFER_SIZE];
        long byteCount = 0;
  
        char c;
        int loop;
        int count;
        StringBuilder sb = new StringBuilder();
  
        while (true)
        {
           count = is.read(buffer);
           if (count == -1)
           {
              break;
           }
  
           byteCount += count;
  
           sb.setLength(0);
  
           for (loop = 0; loop < count; loop++)
           {
              sb.append(" ");
              sb.append(HEX_DIGITS[(buffer[loop] & 0xF0) >> 4]);
              sb.append(HEX_DIGITS[buffer[loop] & 0x0F]);
           }
  
           while (loop < BUFFER_SIZE)
           {
              sb.append("   ");
              ++loop;
           }
  
           sb.append("   ");
  
           for (loop = 0; loop < count; loop++)
           {
              c = (char) buffer[loop];
              if (c > 200 || c < 27)
              {
                 c = ' ';
              }
  
              sb.append(c);
           }
  
           pw.println(sb.toString());
        }
  
        return (byteCount);
     }
docs: This method dumps the entire contents of a file to an output
  print writer as hex and ASCII data.
  
  @param is Input Stream
  @param pw Output PrintWriter
  @return number of bytes read
  @throws Exception Thrown on file read errors