All Packages Class Hierarchy This Package Previous Next Index
Class HTTPClient.HttpOutputStream
java.lang.Object
|
+----java.io.OutputStream
|
+----HTTPClient.HttpOutputStream
- public class HttpOutputStream
- extends OutputStream
- implements GlobalConstants
This class provides an output stream for requests. The stream must first
be associated with a request before it may be used; this is done by
passing it to one of the request methods in HTTPConnection.
There are two constructors for this class, one taking a length parameter
and one without any parameters. If the stream is created with a length
then the request will be sent with the corresponding Content-length header
and anything written to the stream will be written on the socket immediately.
This is the preferred way. If the stream is created without a length then
one of two things will happen: if, at the time of the request, the server
is known to understand HTTP/1.1 then each write() will send the data
immediately using the chunked encoding. If, however, either the server
version is unknown (because this is first request to that server) or the
server only understands HTTP/1.0 then all data will be written to a buffer
first, and only when the stream is closed will the request be sent.
Another reason that using the HttpOutputStream(length)
constructor is recommended over the HttpOutputStream() one is
that some HTTP/1.1 servers do not allow the chunked transfer encoding to
be used when POSTing to a cgi script. This is because the way the cgi API
is defined the cgi script expects a Content-length environment variable.
If the data is sent using the chunked transfer encoding however, then the
server would have to buffer all the data before invoking the cgi so that
this variable could be set correctly. Not all servers are willing to do
this.
The behaviour of a request sent with an output stream may differ from
that of request sent with a data parameter. The reason for this is that
the various modules cannot resend a request which used an output stream.
Therefore such things as authorization and retrying of requests won't be
done by the HTTPClient for such a request.
- Since:
- V0.3
- Version:
- 0.3 30/01/1998
- Author:
- Ronald Tschalär
-
HttpOutputStream()
- Creates an output stream of unspecified length.
-
HttpOutputStream(int)
- This creates an output stream which will take length bytes
of data.
-
close()
- Closes the stream and causes the data to be sent if it has not already
been done so.
-
getLength()
- Returns the number of bytes this stream is willing to accept, or -1
if it is unbounded.
-
toString()
- produces a string describing this stream.
-
write(byte[], int, int)
- Writes an array of bytes on the stream.
-
write(int)
- Writes a single byte on the stream.
HttpOutputStream
public HttpOutputStream()
- Creates an output stream of unspecified length. Note that it is
highly recommended that this constructor be avoided
where possible and
HttpOutputStream(int)
used instead.
- See Also:
- HttpOutputStream
HttpOutputStream
public HttpOutputStream(int length)
- This creates an output stream which will take length bytes
of data.
- Parameters:
- length - the number of bytes which will be sent over this stream
getLength
public int getLength()
- Returns the number of bytes this stream is willing to accept, or -1
if it is unbounded.
- Returns:
- the number of bytes
write
public void write(int b) throws IOException, IllegalAccessError
- Writes a single byte on the stream. It is subject to the same rules
as
write(byte[], int, int)
.
- Parameters:
- b - the byte to write
- Throws:
IOException
- if any exception is thrown by the socket
- Overrides:
- write in class OutputStream
- See Also:
- write
write
public void write(byte[] buf,
int off,
int len) throws IOException, IllegalAccessError
- Writes an array of bytes on the stream. This method may not be used
until this stream has been passed to one of the methods in
HTTPConnection (i.e. until it has been associated with a request).
- Parameters:
- buf - an array containing the data to write
- off - the offset of the data whithin the buffer
- len - the number bytes (starting at off) to write
- Throws:
IOException
- if any exception is thrown by the socket, or
if writing len bytes would cause more bytes to
be written than this stream is willing to accept.
- Throws:
IllegalAccessError
- if this stream has not been associated
with a request yet
- Overrides:
- write in class OutputStream
close
public void close() throws IOException, IllegalAccessError
- Closes the stream and causes the data to be sent if it has not already
been done so. This method must be invoked when all
data has been written.
- Throws:
IOException
- if any exception is thrown by the underlying
socket, or if too few bytes were written.
- Throws:
IllegalAccessError
- if this stream has not been associated
with a request yet.
- Overrides:
- close in class OutputStream
toString
public String toString()
- produces a string describing this stream.
- Returns:
- a string containing the name and the length
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index