----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

Here's a fix for JServInputStream. I've given it limited testing and it
appears to correct the problem.

The idea is pass the content-length in on the constructor or
JServInputStream and then track the data as it is consumed. When it's all
gone, start returning 0's. The unknown content-length of -1 also needs to be
supported since most requests are in that mode.

// Set up the servlet's I/O streams
servlet_in = new JServInputStream(getContentLength(), in);


/**
 * ServletInputStream implementation as inner class
 */
 protected class JServInputStream extends ServletInputStream {

    protected InputStream in;
    protected int length;

    public JServInputStream(int length, InputStream in) {
        this.length = length;
        this.in = in;
    }

    public int read() throws IOException

        if ((length-- > 0) || (length == -1))
            return in.read();
        return -1;
    }

    public int read(byte b[]) throws IOException {
        if (length == -1)
            return in.read(b, 0, b.length);

        int len = b.length;
        if (len > length)
            len = length;
        length -= len;
        if (len > 0)
            return in.read(b, 0, len);
        return 0;
    }

    public int read(byte b[], int off, int len) throws IOException {
        if (length == -1)
            return in.read(b, off, len);

        if (len > length)
            len = length;
        length -= len;
        if (len > 0)
            return in.read(b,off,len);
        return 0;
    }

    public long skip(long n) throws IOException {
        if (length == -1)
            return in.skip(n);

        if (n > length)
            n = length;
        length -= n;
        if (n > 0)
            return in.skip(n);
        return 0;
    }

    public void close() throws IOException {
        // Ignore closing of the input stream since it also
        // close the output stream.
        // conn.in.close();
    }

    /**
        We must implement this method because java.io.InputStream
        javadocs says that this will return 0. Since we use a long
        internally, it must be cast to an int. ugly. -JSS
    */
    public int available() throws IOException {
        if (length == -1)
            return in.available();
        return length;
    }
}

Jon Smirl
[EMAIL PROTECTED]




--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to