/ blog / java / inputstreams-suck.html

Root Beer Logo Root Beer

Chris Nokleberg's Fizzy Weblog

April 2003
Su M Tu W Th F Sa
    3 5
6 7 8 10 11 12
14 15 16 17 19
20 21 22 23 24 25 26
27 28 29 30
Previous  |  Next  |  More...
#  InputStreams suck

...but some suck faster than others.

One aspect of the InputStream API that people (e.g. myself) often forget about is that the read(byte[] b, int off, int len) method can return less than the requested number of bytes. Unfortunately, the problem does not usually manifest itself because the underlying streams aren't typically blocked waiting for data. It is particularly insidious in that everything may appear fine when testing, because (for instance) your web browser and server are on the same fast local area network, but once some real-world modem-bound users hit your application, all hell breaks loose.

To find all such bugs once and for all, I wrote a SlowInputStream class. It will wrap any stream and simply returns a random portion of the data that is actually requested. All properly written Java code should continue to work, but problematic code will suddenly start breaking in various bizarre ways.

[Powered By FreeMarker]  [Valid Atom 1.0]  [Weblog Commenting by]