Commit 5d7b2198 by Michael Koch Committed by Michael Koch

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.

From-SVN: r76412
parent 8fac50e0
2004-01-23 Michael Koch <konqueror@gmx.de> 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 * java/io/FileDescriptor.java
(in, out, err): Added javadoc. (in, out, err): Added javadoc.
(static): Merged loading code. (static): Merged loading code.
......
...@@ -168,7 +168,6 @@ public final class Connection extends HttpURLConnection ...@@ -168,7 +168,6 @@ public final class Connection extends HttpURLConnection
inputStream = inputStream =
new DataInputStream(new BufferedInputStream(socket.getInputStream())); new DataInputStream(new BufferedInputStream(socket.getInputStream()));
outputStream = new BufferedOutputStream (socket.getOutputStream()); outputStream = new BufferedOutputStream (socket.getOutputStream());
bufferedOutputStream = new ByteArrayOutputStream (256); //default is too small
sendRequest(); sendRequest();
receiveReply(); receiveReply();
...@@ -226,7 +225,8 @@ public final class Connection extends HttpURLConnection ...@@ -226,7 +225,8 @@ public final class Connection extends HttpURLConnection
setRequestProperty ("Content-type", "application/x-www-form-urlencoded"); setRequestProperty ("Content-type", "application/x-www-form-urlencoded");
// Set correct content length. // 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. // Write all req_props name-value pairs to the output writer.
Iterator itr = getRequestProperties().entrySet().iterator(); Iterator itr = getRequestProperties().entrySet().iterator();
...@@ -242,8 +242,11 @@ public final class Connection extends HttpURLConnection ...@@ -242,8 +242,11 @@ public final class Connection extends HttpURLConnection
outputWriter.flush(); outputWriter.flush();
// Write content // Write content
bufferedOutputStream.writeTo (outputStream); if (bufferedOutputStream != null)
outputStream.flush(); {
bufferedOutputStream.writeTo (outputStream);
outputStream.flush();
}
} }
/** /**
...@@ -382,12 +385,16 @@ public final class Connection extends HttpURLConnection ...@@ -382,12 +385,16 @@ public final class Connection extends HttpURLConnection
*/ */
public OutputStream getOutputStream() throws IOException public OutputStream getOutputStream() throws IOException
{ {
if (connected)
throw new ProtocolException
("You cannot get an outputstream for an existing http connection");
if (!doOutput) if (!doOutput)
throw new ProtocolException throw new ProtocolException
("Want output stream while haven't setDoOutput(true)"); ("Want output stream while haven't setDoOutput(true)");
if (!connected) if (bufferedOutputStream == null)
connect(); bufferedOutputStream = new ByteArrayOutputStream (256); //default is too small
return bufferedOutputStream; return bufferedOutputStream;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment