> Interesting.
>
> I don't know what available() does either, but I'd be surprised if its
> behaviour changes just because its object is re-cast.
>
> Of course, I must be missing something here.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
cdsmith@twu.net wrote in comp.lang.java.programmer:
> I don't see this as an anti-pattern. The original author made a trade-
> off between flexibility and performance.
But think for a second what flexibility was traded off? Surely a
ByteArrayInputStream can be used where an InputStream is needed,
but not vice versa. So no flexibility for the class user was
added (quite the opposite, flexibility was lost). The reason why
the author used InputStream was because he expected the
implementation to change (which never happened). In this question
changing the implementation to something else would have required
a massive redesign.
Or then the author was just having "OOP blindness". In other
words, used InputStream because every _interface_ he has seen
uses it.
> But that doesn't mean that we can categorize that whole family of
> decisions as being a bad idea.
Please describe the "family of decisions" you are talking about.
I think you understood me incorrectly and would like to correct
it.

Signature
Antti S. Brax Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/
[1385 messages expunged from folder "Spam"]
Chris Smith - 30 Sep 2005 16:17 GMT
> cdsmith@twu.net wrote in comp.lang.java.programmer:
> > I don't see this as an anti-pattern. The original author made a trade-
> > off between flexibility and performance.
>
> But think for a second what flexibility was traded off?
Flexibility in the implementation of that declared API. Whether that
flexibility is required is a decision that involves various trade-offs.
I tend to side with Chris Uppal's statement though: it would make sense
to return InputStream or to return byte[], but I can't imagine it being
appropriate to return a ByteArrayInputStream.
> The reason why
> the author used InputStream was because he expected the
> implementation to change (which never happened).
Yet.
> Please describe the "family of decisions" you are talking about.
> I think you understood me incorrectly and would like to correct
> it.
The family could be described as decisions that withhold information
from the client of an API in order to preserve the ability to change the
implementation later. That's what you're talking about, right?

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
> The ByteArrayInputStream class fulfills all the requirements of
> the superclass (i.e., it returns the number of bytes that can be read
> without blocking)... but it also makes the additional guarantee that it
> returns the number of bytes remaining in the complete stream. Antti
> wants to use that guarantee...
I cannot find that guarantee in the Javadoc.
Yes, perusing the source, it is obvious it is there.
In this case it is highly unlikely you would ever come across an
implementation that does not make the same guarantee,
but relying on undocumented implementation specific behaviour
can often come back and bite you.
Almost makes me think it might be an anti-pattern...
Antti S. Brax - 30 Sep 2005 11:06 GMT
spamtrap@xenoc.demon.co.uk.invalid wrote in comp.lang.java.programmer:
>> The ByteArrayInputStream class fulfills all the requirements of
>> the superclass (i.e., it returns the number of bytes that can be read
[quoted text clipped - 10 lines]
> can often come back and bite you.
> Almost makes me think it might be an anti-pattern...
Well, your inability to understand documentation could also
be thought as an anti-pattern.
available(): The value returned is count - pos, which is the
number of bytes remaining to be read from the input buffer.
count: The index one greater than the last valid character in
the input stream buffer.
pos: The index of the next character to read from the input
stream buffer.
I think it is quite clearly stated in the documentation.

Signature
Antti S. Brax Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/
[1385 messages expunged from folder "Spam"]
Thomas Schodt - 30 Sep 2005 11:33 GMT
> your inability to understand documentation could also
> be thought as an anti-pattern.
Amazing.
It is beyond belief that I looked at the entry several times
and completely missed what it was saying.
I had it in front of me and had to ask the browser to search for "The
value returned"...
Talk about a blind spot.