You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@xml.apache.org by Keith Thomas <K...@XOL.com> on 2000/09/26 07:39:15 UTC

readLine() in IOUtils problematic

Hi,

I try and be a SOAP client to various server systems. One of these server
systems does to not always seem produce an 'end of line' or 'carriage
return' on the very end of it's envelope. Hence, the final readLine() in
IOUtils does not work as intended. I have coded my own solution to this,
which involves using the respContentLength stored in HTTPUtils.Response to
read the appropriate number of characters via a read() instead of a
readLine(),

    public static String getStringFromReader(Reader reader, 
               int messageLength) throws IOException {
        BufferedReader bufIn = new BufferedReader(reader);
        StringWriter swOut = new StringWriter();
        PrintWriter pwOut = new PrintWriter(swOut);
        String tempLine;
        char[] cbuff = new char[messageLength];
        int lengthRead = 0;

        while (lengthRead < messageLength) {
            int lengthToRead = cbuff.length;
            if (messageLength - lengthRead < cbuff.length)
                lengthToRead = messageLength - lengthRead;
            int rc = bufIn.read(cbuff, 0, lengthToRead);
            tempLine = new String(cbuff);
            pwOut.print(tempLine.substring(0, rc));
            lengthRead = lengthRead + rc;
        } //(lengthRead < messageLength))

        pwOut.flush();
        return swOut.toString();
    } // getStringFromReader(...)

Whilst this works great for me, as does my modifcation to HTTPUtils so that
it uses the HTTPUrlConnection class, I am blissfully unaware of the
big-picture ramifications of such changes being made to the base source
code. 

Please let me know whether or not it's worth me tidying up my changes and
submitting them for consideration for inclusion in this fine project.

Thanks,
Keith Thomas
Xtra On-Line
Denver, CO, USA