diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-01-23 12:32:23 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-01-23 12:32:23 +0000 |
commit | b1a91cddb18bc6292741ee21d05259f397b13e32 (patch) | |
tree | 864103fde84c0fd65c6c0e8f345b49f80e9dca9a /libjava/gnu/java/net/protocol/http/Connection.java | |
parent | 98aac82dc2338e8acf341afe9130d02dd62dbf9b (diff) | |
download | ppe42-gcc-b1a91cddb18bc6292741ee21d05259f397b13e32.tar.gz ppe42-gcc-b1a91cddb18bc6292741ee21d05259f397b13e32.zip |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@76412 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu/java/net/protocol/http/Connection.java')
-rw-r--r-- | libjava/gnu/java/net/protocol/http/Connection.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/libjava/gnu/java/net/protocol/http/Connection.java b/libjava/gnu/java/net/protocol/http/Connection.java index b785f2334bf..bc58ebd8bb7 100644 --- a/libjava/gnu/java/net/protocol/http/Connection.java +++ b/libjava/gnu/java/net/protocol/http/Connection.java @@ -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; } |