classpath-inetlib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Classpath-inetlib] Problems in gnu.inet.util.LineInputStream and gn


From: Chris Burdess
Subject: Re: [Classpath-inetlib] Problems in gnu.inet.util.LineInputStream and gnu.inet.util.CRLFInputStream
Date: Sun, 3 Apr 2005 10:47:44 +0100

Robert Mitchell wrote:

The readLine method for LineInputStream contains the following code:
 
            len = in.available();
            len = (len < MIN_LENGTH) ? MIN_LENGTH : len;

 
This has the effect of reading the entire wrapped stream in order to find one line.

Not according to the documentation for InputStream.available, unless all the bytes in the stream are immediately available for reading, in which case they will all be read.

I suggest two changes.  First, the above lines should be replaced by:
 
            len = in.available();
            len = (len > MIN_LENGTH) ? MIN_LENGTH : len;

and presumably changing the name of MIN_LENGTH to MAX_LENGTH?

It may be useful to specify both a minimum /and/ a maximum, but your patch will cause problems when in.available() returns 0.

Second, I am attaching a replacement for CRLFInputStream that corrects both the inefficiencies of removeCRLF and the problems with read(byte[], int, int).  The first is fixed by making sure to only copy bytes once to remove CR, instead of copying them for each CR removed ahead of them.  The second is fixed by passing the correct length to removeCRLF.  To avoid an infinite loop problem with a CR at the end of a buffer, it reads the next character instead of buffering the CR.  To avoid possible problems with mark/reset caused by this, it adds one to the requested readahead limit.  (Note this does not deal with potential problems with interactions between the single byte read() - which can read 2 bytes - and mark/reset.)

I'm interested in this, but please could you provide a patch against the current source? The file you attached is encoded with CRs at the end of every line so I can't diff it against the original.
--
Chris Burdess





reply via email to

[Prev in Thread] Current Thread [Next in Thread]