You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2004/09/06 19:41:45 UTC

cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpConnection.java

olegk       2004/09/06 10:41:45

  Modified:    httpclient/src/java/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH HttpConnection.java
  Log:
  PR #21329 (Add InputStream buffering)
  
  Contributed by Bjarne Rasmussen <brasmussen -at- novell.com>
  Reviewed bt Oleg Kalnichevski & Michael Becke
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.67.2.13 +26 -10    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.67.2.12
  retrieving revision 1.67.2.13
  diff -u -r1.67.2.12 -r1.67.2.13
  --- HttpConnection.java	19 Jul 2004 20:06:26 -0000	1.67.2.12
  +++ HttpConnection.java	6 Sep 2004 17:41:45 -0000	1.67.2.13
  @@ -31,12 +31,12 @@
   
   package org.apache.commons.httpclient;
   
  +import java.io.BufferedInputStream;
   import java.io.BufferedOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.InterruptedIOException;
   import java.io.OutputStream;
  -import java.io.PushbackInputStream;
   import java.lang.reflect.Method;
   import java.net.InetAddress;
   import java.net.Socket;
  @@ -498,13 +498,14 @@
                   if (inputStream.available() == 0) {
                       try {
                           socket.setSoTimeout(1);
  +                        inputStream.mark(1);
                           int byteRead = inputStream.read();
                           if (byteRead == -1) {
                               // again - if the socket is reporting all data read,
                               // probably stale
                               isStale = true;
                           } else {
  -                            inputStream.unread(byteRead);
  +                            inputStream.reset();
                           }
                       } finally {
                           socket.setSoTimeout(soTimeout);
  @@ -686,7 +687,14 @@
               if (outbuffersize > 2048) {
                   outbuffersize = 2048;
               }
  -            inputStream = new PushbackInputStream(socket.getInputStream());
  +            int inbuffersize = socket.getReceiveBufferSize();
  +            if (inbuffersize > 2048) {
  +                inbuffersize = 2048;
  +            }
  +            inputStream = new BufferedInputStream(
  +                socket.getInputStream(),
  +                inbuffersize
  +            );
               outputStream = new BufferedOutputStream(
                   new WrappedOutputStream(socket.getOutputStream()),
                   outbuffersize
  @@ -743,7 +751,14 @@
           if (outbuffersize > 2048) {
               outbuffersize = 2048;
           }
  -        inputStream = new PushbackInputStream(socket.getInputStream());
  +        int inbuffersize = socket.getReceiveBufferSize();
  +        if (inbuffersize > 2048) {
  +            inbuffersize = 2048;
  +        }
  +        inputStream = new BufferedInputStream(
  +            socket.getInputStream(),
  +            inbuffersize
  +        );
           outputStream = new BufferedOutputStream(
               new WrappedOutputStream(socket.getOutputStream()),
               outbuffersize
  @@ -884,9 +899,10 @@
           } else {
               try {
                   this.socket.setSoTimeout(timeout);
  +                inputStream.mark(1);
                   int byteRead = inputStream.read();
                   if (byteRead != -1) {
  -                    inputStream.unread(byteRead);
  +                    inputStream.reset();
                       LOG.debug("Input data available");
                       result = true;
                   } else {
  @@ -1389,7 +1405,7 @@
       private Socket socket = null;
       
       /** My InputStream. */
  -    private PushbackInputStream inputStream = null;
  +    private InputStream inputStream = null;
   
       /** My OutputStream. */
       private OutputStream outputStream = null;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org