|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unkrig.commons.net.http.HttpMessage
public class HttpMessage
Representation of an HTTP request or response.
| Nested Class Summary | |
|---|---|
static interface |
HttpMessage.Body
The life cycle of a HttpMessage.Body is as follows:
Create the object by calling one of the following methods:
body(String, Charset)
body(InputStream)
body(File)
body(ConsumerWhichThrows)
Call exactly one of the following methods:
HttpMessage.Body.string(Charset)
HttpMessage.Body.inputStream()
HttpMessage.Body.write(OutputStream)
HttpMessage.Body.dispose()
Call HttpMessage.Body.dispose() as many times as you want
Otherwise, a resource leak will occur. |
| Field Summary | |
|---|---|
static HttpMessage.Body |
EMPTY_BODY
Representation of an empty HTTP request/response body. |
static HttpMessage.Body |
NO_BODY
Representation of a non-existent HTTP request/response body. |
| Constructor Summary | |
|---|---|
protected |
HttpMessage(boolean hasBody)
Constructor for outgoing messages. |
protected |
HttpMessage(java.io.InputStream in,
boolean hasHeaders,
boolean hasBody)
Constructor for incoming messages. |
| Method Summary | |
|---|---|
void |
addHeader(java.lang.String name,
java.util.Date value)
Appends another HTTP header. |
void |
addHeader(java.lang.String name,
int value)
Appends another HTTP header. |
void |
addHeader(java.lang.String name,
long value)
Appends another HTTP header. |
void |
addHeader(java.lang.String name,
java.lang.String value)
Appends another HTTP header. |
static HttpMessage.Body |
body(ConsumerWhichThrows<java.io.OutputStream,java.io.IOException> writer)
|
static HttpMessage.Body |
body(java.io.File file)
|
static HttpMessage.Body |
body(java.io.InputStream in)
|
static HttpMessage.Body |
body(java.lang.String text,
java.nio.charset.Charset charset)
|
java.nio.charset.Charset |
getCharset()
Determines the charset from the "Content-Type" header. |
java.util.Date |
getDateHeader(java.lang.String name)
|
java.lang.String |
getHeader(java.lang.String name)
|
java.util.List<MessageHeader> |
getHeaders()
The returned list is backed by the HttpMessage! |
java.lang.String[] |
getHeaders(java.lang.String name)
|
int |
getIntHeader(java.lang.String name)
|
long |
getLongHeader(java.lang.String name)
|
protected void |
readBody(java.nio.channels.ReadableByteChannel in,
Multiplexer multiplexer,
RunnableWhichThrows<java.io.IOException> finished)
Reads the body contents of this message into a buffer (depending on the 'Content-Length' and 'Transfer-Encoding' headers). |
static void |
readHeaders(java.nio.channels.ReadableByteChannel in,
Multiplexer multiplexer,
ConsumerWhichThrows<java.util.List<MessageHeader>,java.io.IOException> consumer)
Reads HTTP headers up to and including the terminating empty line. |
static java.lang.String |
readLine(java.io.InputStream in)
|
static void |
readLine(java.nio.channels.ReadableByteChannel in,
Multiplexer multiplexer,
ConsumerWhichThrows<java.lang.String,java.io.IOException> lineConsumer)
Reads one HTTP request from in through the multiplexer and passes it to the requestConsumer. |
HttpMessage.Body |
removeBody()
Removes the body from this HttpMessage for analysis or modification. |
void |
removeHeader(java.lang.String name)
Remove all headers with the given name. |
void |
setBody(HttpMessage.Body body)
Disposes the current body of this message and adopts the given HttpMessage.Body object as the new body. |
void |
setHeader(java.lang.String name,
java.util.Date value)
Changes the value of the first header with the given name. |
void |
setHeader(java.lang.String name,
int value)
Changes the value of the first header with the given name. |
void |
setHeader(java.lang.String name,
long value)
Changes the value of the first header with the given name. |
void |
setHeader(java.lang.String name,
java.lang.String value)
Changes the value of the first header with the given name. |
protected void |
writeHeadersAndBody(java.lang.String prefix,
java.io.OutputStream out)
Writes this message's headers and body to the given OutputStream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final HttpMessage.Body NO_BODY
public static final HttpMessage.Body EMPTY_BODY
| Constructor Detail |
|---|
protected HttpMessage(boolean hasBody)
protected HttpMessage(java.io.InputStream in,
boolean hasHeaders,
boolean hasBody)
throws java.io.IOException
java.io.IOException| Method Detail |
|---|
public void addHeader(java.lang.String name,
java.lang.String value)
public void addHeader(java.lang.String name,
int value)
public void addHeader(java.lang.String name,
long value)
public void addHeader(java.lang.String name,
java.util.Date value)
public void setHeader(java.lang.String name,
java.lang.String value)
name.
public void setHeader(java.lang.String name,
int value)
name.
public void setHeader(java.lang.String name,
long value)
name.
public void setHeader(java.lang.String name,
java.util.Date value)
name.
public void removeHeader(java.lang.String name)
name.
@Nullable public final java.lang.String getHeader(java.lang.String name)
name, or null
public int getIntHeader(java.lang.String name)
throws java.io.IOException
-1 iff a header with this name does not exist
java.io.IOException
public final long getLongHeader(java.lang.String name)
throws java.io.IOException
-1L iff a header with this name does not exist
java.io.IOException
@Nullable
public java.util.Date getDateHeader(java.lang.String name)
throws java.io.IOException
null iff a header with this name does not exist
java.io.IOExceptionpublic java.lang.String[] getHeaders(java.lang.String name)
name, or an empty arraypublic java.util.List<MessageHeader> getHeaders()
HttpMessage!
public HttpMessage.Body removeBody()
HttpMessage for analysis or modification. It can later be re-attached to
the same (or a different) HttpMessage through setBody(Body).
public static HttpMessage.Body body(java.lang.String text,
java.nio.charset.Charset charset)
HttpMessage.Bodypublic static HttpMessage.Body body(java.io.InputStream in)
HttpMessage.Body
public static HttpMessage.Body body(java.io.File file)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionHttpMessage.Bodypublic static HttpMessage.Body body(ConsumerWhichThrows<java.io.OutputStream,java.io.IOException> writer)
HttpMessage.Bodypublic void setBody(HttpMessage.Body body)
HttpMessage.Body object as the new body.
public java.nio.charset.Charset getCharset()
protected void writeHeadersAndBody(java.lang.String prefix,
java.io.OutputStream out)
throws java.io.IOException
OutputStream.
java.io.IOException
public static java.lang.String readLine(java.io.InputStream in)
throws java.io.IOException
java.io.IOException
public static void readLine(java.nio.channels.ReadableByteChannel in,
Multiplexer multiplexer,
ConsumerWhichThrows<java.lang.String,java.io.IOException> lineConsumer)
throws java.io.IOException
in through the multiplexer and passes it to the requestConsumer.
java.io.IOException
public static void readHeaders(java.nio.channels.ReadableByteChannel in,
Multiplexer multiplexer,
ConsumerWhichThrows<java.util.List<MessageHeader>,java.io.IOException> consumer)
throws java.io.IOException
java.io.IOException
protected void readBody(java.nio.channels.ReadableByteChannel in,
Multiplexer multiplexer,
RunnableWhichThrows<java.io.IOException> finished)
throws java.io.IOException
java.io.IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||