Work with BufferedInputStreams and IJ1 char set

Code now relies on buffered input (because it must read stream twice).
While at it I restored IJ1's character set for tokens. This means that
tables with headers now work once again.
Improve stream close handling
Make histogram size calc code more clear
Clean up some ugly code
Merge branch 'quick-fixes'