• Post Reply Bookmark Topic Watch Topic
  • New Topic

byte or character stream?  RSS feed

 
Flora Ng
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
In order to monitor the progress of the reading/downloading of a file/html & do some checking at the same time, which stream should be used?
Which method is for checking the file/html size?
Thanks in advance.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For monitoring progress, either one will do, since exact values rarely matter here anyway - if 40% of the bytes in a file have been downloaded, then very close to 40% of the characters have been read. (Depending on character encoding used, each character may take one to three bytes to encode. But whatever the ratio, it's generally about the same on average within a given file. Unless the first half of the file is in English and the latter half in Japanese - then you might get somewhat different results.
However, if you want to report the "size" of a file, this is almost universally understood to mean the number of bytes - in which case you should count the bytes passed through a byte stream. A good way to do this while downloading is to create a FilterInputStream which increments a counter for every byte read, but otherwise has no effect on the underlying stream.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!