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

FW: readLine() in IOUtils problematic

Sorry to bother you on your developers list, but I got zero responses to
this posting on the users list. I know my code is not the most efficient or
robust piece of work ever but I think the concept is sound. Please let me
know your thoughts, kind or unkind.

Keith Thomas

-----Original Message-----
From: Keith Thomas 
Sent: Monday, September 25, 2000 11:39 PM
To: 'soap-user@xml.apache.org'
Subject: 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

Re: FW: readLine() in IOUtils problematic

Posted by George I Matkovits <ma...@uswest.net>.
What are the endpoint systems, please? The CR conventions are different between
Unix (Linux) and Windows. We had a  bug like this in the original IBM code. We
might have a similar one somewhere else? I will try and look at your code later
this week, sorry but I just do not have the time now! (-:
Regards - George

Keith Thomas wrote:

> Sorry to bother you on your developers list, but I got zero responses to
> this posting on the users list. I know my code is not the most efficient or
> robust piece of work ever but I think the concept is sound. Please let me
> know your thoughts, kind or unkind.
>
> Keith Thomas
>
> -----Original Message-----
> From: Keith Thomas
> Sent: Monday, September 25, 2000 11:39 PM
> To: 'soap-user@xml.apache.org'
> Subject: 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


Re: FW: readLine() in IOUtils problematic

Posted by George I Matkovits <ma...@uswest.net>.
What are the endpoint systems, please? The CR conventions are different between
Unix (Linux) and Windows. We had a  bug like this in the original IBM code. We
might have a similar one somewhere else? I will try and look at your code later
this week, sorry but I just do not have the time now! (-:
Regards - George

Keith Thomas wrote:

> Sorry to bother you on your developers list, but I got zero responses to
> this posting on the users list. I know my code is not the most efficient or
> robust piece of work ever but I think the concept is sound. Please let me
> know your thoughts, kind or unkind.
>
> Keith Thomas
>
> -----Original Message-----
> From: Keith Thomas
> Sent: Monday, September 25, 2000 11:39 PM
> To: 'soap-user@xml.apache.org'
> Subject: 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


Re: FW: readLine() in IOUtils problematic

Posted by Dennisf <de...@nj.paradyne.com>.
how about this ?

public gets (BufferedReader in, int len, String encoding) throws IOException
{
        byte[]      b;
        int            l,         // number of ALL bytes read
                       m;       // number of CURRENTLY available bytes
         long        t1; // time since last batch("m" long) of bytes was read

         l = 0;
         b = new byte[len];
         t1 = new java.util.Date().getTime();
         while (l <= len)
         {
                  if ((m = in.available()) <= 0)
                  {
                           try { Thread.currentThread().sleep(64); } catch
(InterruptedException _e) { /* ignore */ }
                           if (new java.util.Date().getTime() - t1)/1000 >=
MAX_TIMEOUT)
                                    throw IllegalStateException(MAX_TIMEOUT_MSG);

                           continue;
                  }
                  if (m > (len - l)) m = len - l;
                  in.read(b, l, m);
                  l += m;
                  t1 = new java.util.Date().getTime();
         }
         return (encoding == null ? new String(b) : new String(b, encoding));
}

Dennisf wrote:

> Keith Thomas wrote:
>
> > Sorry to bother you on your developers list, but I got zero responses to
> > this posting on the users list. I know my code is not the most efficient or
> > robust piece of work ever but I think the concept is sound. Please let me
> > know your thoughts, kind or unkind.
> >
> > Keith Thomas
> >
> > -----Original Message-----
> > From: Keith Thomas
> > Sent: Monday, September 25, 2000 11:39 PM
> > To: 'soap-user@xml.apache.org'
> > Subject: 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


Re: FW: readLine() in IOUtils problematic

Posted by Dennisf <de...@nj.paradyne.com>.
how about this ?

public gets (BufferedReader in, int len, String encoding) throws IOException
{
        byte[]      b;
        int            l,         // number of ALL bytes read
                       m;       // number of CURRENTLY available bytes
         long        t1; // time since last batch("m" long) of bytes was read

         l = 0;
         b = new byte[len];
         t1 = new java.util.Date().getTime();
         while (l <= len)
         {
                  if ((m = in.available()) <= 0)
                  {
                           try { Thread.currentThread().sleep(64); } catch
(InterruptedException _e) { /* ignore */ }
                           if (new java.util.Date().getTime() - t1)/1000 >=
MAX_TIMEOUT)
                                    throw IllegalStateException(MAX_TIMEOUT_MSG);

                           continue;
                  }
                  if (m > (len - l)) m = len - l;
                  in.read(b, l, m);
                  l += m;
                  t1 = new java.util.Date().getTime();
         }
         return (encoding == null ? new String(b) : new String(b, encoding));
}

Dennisf wrote:

> Keith Thomas wrote:
>
> > Sorry to bother you on your developers list, but I got zero responses to
> > this posting on the users list. I know my code is not the most efficient or
> > robust piece of work ever but I think the concept is sound. Please let me
> > know your thoughts, kind or unkind.
> >
> > Keith Thomas
> >
> > -----Original Message-----
> > From: Keith Thomas
> > Sent: Monday, September 25, 2000 11:39 PM
> > To: 'soap-user@xml.apache.org'
> > Subject: 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


Re: FW: readLine() in IOUtils problematic

Posted by Dennisf <de...@nj.paradyne.com>.

Keith Thomas wrote:

> Sorry to bother you on your developers list, but I got zero responses to
> this posting on the users list. I know my code is not the most efficient or
> robust piece of work ever but I think the concept is sound. Please let me
> know your thoughts, kind or unkind.
>
> Keith Thomas
>
> -----Original Message-----
> From: Keith Thomas
> Sent: Monday, September 25, 2000 11:39 PM
> To: 'soap-user@xml.apache.org'
> Subject: 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


Re: FW: readLine() in IOUtils problematic

Posted by Dennisf <de...@nj.paradyne.com>.

Keith Thomas wrote:

> Sorry to bother you on your developers list, but I got zero responses to
> this posting on the users list. I know my code is not the most efficient or
> robust piece of work ever but I think the concept is sound. Please let me
> know your thoughts, kind or unkind.
>
> Keith Thomas
>
> -----Original Message-----
> From: Keith Thomas
> Sent: Monday, September 25, 2000 11:39 PM
> To: 'soap-user@xml.apache.org'
> Subject: 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