2004-01-23 Michael Koch <konqueror@gmx.de>
authorMichael Koch <konqueror@gmx.de>
Fri, 23 Jan 2004 12:32:23 +0000 (12:32 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Fri, 23 Jan 2004 12:32:23 +0000 (12:32 +0000)
* gnu/java/net/protocol/http/Connection.java
(connect): Don't initialize bufferedOutputStream if not needed.
(sendRequest): Set property for content length if content is present.
Write content only if present.
(getOutputStream): Check if already connected, dont connect,
initalize bufferedOutputStream if needed.

From-SVN: r76412

libjava/ChangeLog
libjava/gnu/java/net/protocol/http/Connection.java

index fe374fd80817bf9e30445ee39d7e7244813dc16e..6ed347af690f3a771828a3b586d3a163cbbebf12 100644 (file)
@@ -1,3 +1,12 @@
+2004-01-23  Michael Koch  <konqueror@gmx.de>
+
+       * gnu/java/net/protocol/http/Connection.java
+       (connect): Don't initialize bufferedOutputStream if not needed.
+       (sendRequest): Set property for content length if content is present.
+       Write content only if present.
+       (getOutputStream): Check if already connected, dont connect,
+       initalize bufferedOutputStream if needed.
+
 2004-01-23  Michael Koch  <konqueror@gmx.de>
 
        * java/io/FileDescriptor.java
index b785f2334bf37c8a37de7cc3016352fd26c36b37..bc58ebd8bb71e7b15777efdd3de3356f5ba055ac 100644 (file)
@@ -168,7 +168,6 @@ public final class Connection extends HttpURLConnection
     inputStream =
       new DataInputStream(new BufferedInputStream(socket.getInputStream()));
     outputStream = new BufferedOutputStream (socket.getOutputStream());
-    bufferedOutputStream = new ByteArrayOutputStream (256); //default is too small
 
     sendRequest();
     receiveReply();
@@ -226,7 +225,8 @@ public final class Connection extends HttpURLConnection
       setRequestProperty ("Content-type", "application/x-www-form-urlencoded");
 
     // Set correct content length.
-    setRequestProperty ("Content-length", String.valueOf (bufferedOutputStream.size()));
+    if (bufferedOutputStream != null)
+      setRequestProperty ("Content-length", String.valueOf (bufferedOutputStream.size()));
 
     // Write all req_props name-value pairs to the output writer.
     Iterator itr = getRequestProperties().entrySet().iterator();
@@ -242,8 +242,11 @@ public final class Connection extends HttpURLConnection
     outputWriter.flush();
 
     // Write content
-    bufferedOutputStream.writeTo (outputStream);
-    outputStream.flush();
+    if (bufferedOutputStream != null)
+      {
+       bufferedOutputStream.writeTo (outputStream);
+       outputStream.flush();
+      }
   }
 
   /**
@@ -382,12 +385,16 @@ public final class Connection extends HttpURLConnection
    */
   public OutputStream getOutputStream() throws IOException
   {
+    if (connected)
+      throw new ProtocolException
+       ("You cannot get an outputstream for an existing http connection");
+
     if (!doOutput)
       throw new ProtocolException
         ("Want output stream while haven't setDoOutput(true)");
     
-    if (!connected)
-      connect();
+    if (bufferedOutputStream == null)
+      bufferedOutputStream = new ByteArrayOutputStream (256); //default is too small
     
     return bufferedOutputStream;
   }