The problem is that when there is a message, I want to pass the InputStream
on to another class which reads and parses the message. If I already read the
first byte, that is no good. So the option is pushing back, but that is really,
really, ugly so I was hoping someone had a better idea.
On Sun, 09 Apr 2000, CacheMiss at aol.com wrote:
> > I tried using this to read into an array of length 0, but this just returns
> 0
> > right away, so it is no good for us. The only thing left I can think of is
> > to use a PushBackInputStream and read one byte and then bush it back when
> it
> > get's read. But, em, could it get any more annoying?
>
> Can't do that. From Javadoc (jdk 1.2.2 on Win32):
>
> If b is null, a NullPointerException is thrown. If the length of b is zero,
> then no bytes are read and 0 is returned; otherwise, there is an attempt
> to read at least one byte. If no byte is available because the stream is
> at end of file, the value -1 is returned; otherwise, at least one byte is
> read and stored into b.
>
> > Could someone smarter then me please fix this (ConnectionHandler.java -
> L56,
> > we need some way to if the connection has been lost for some reason since
> the
> > stupid available() continues returning 0).
>
> I've talked to some people, and it seems that available(), while fine for
> other InputStreams, is wacky and fairly useless when called on a Socket's
> InputStream.
>
> Note, I have -not- looked at the section of code you mentioned.
>
> try
> {
> incomingAvail = incoming.read(buf);
> if (incomingAvail > 0)
> {
> // do something
> }
> }
> catch (InterruptedIOException ioe)
> {
> // read failed on timeout
> }
>
> if (incomingAvail == -1)
> {
> throw new IOException("Connection closed.");
> }
>
> Set a fairly low timeout using setSoTimeout(), like 50ms, and this works
> okay. Kludgey, maybe... but...
>
> -cm
>
> _______________________________________________
> Freenet-dev mailing list
> Freenet-dev at lists.sourceforge.net
> http://lists.sourceforge.net/mailman/listinfo/freenet-dev
--
Oskar Sandberg
md98-osa at nada.kth.se
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
_______________________________________________
Freenet-dev mailing list
Freenet-dev at lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/freenet-dev