Class Message
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObserver(MessageObserver observer) booleanprotected void<T extends Message>
TcreateMessageSnapshot(T result, Runnable bodyUpdatedCallback, BodyCollectingMessageObserver.Strategy strategy, long limit) abstract <T extends Message>
TcreateSnapshot(Runnable bodyUpdatedCallback, BodyCollectingMessageObserver.Strategy strategy, long limit) voidintgetBody()Probably you want to usegetBodyAsStreamDecoded()instead:Returns the logical body content.As this method has bad performance, it should not be used in any critical component.getName()abstract StringbooleanbooleanbooleanisCSS()booleanbooleanisGzip()booleanisHTML()booleanisHTTP10()booleanisHTTP11()booleanisImage()booleanbooleanisJSON()booleanbooleanbooleanisXML()protected abstract voidvoidread(InputStream in, boolean createBody) If the message is HTTP 1.1 but the header has no information about the content length, then an assumption is made that after the body the server will send an EOF.voidreadBody()voidrelease()preserve synchronized keyword, notify method is calledvoidSets the body.voidsetBodyContent(byte[] content) Sets the body.voidsetErrorMessage(String errorMessage) voidvoidsetReleased(boolean released) voidsetVersion(String version) abstract booleantoString()final voidwrite(OutputStream out, boolean retainBody) voidThe start line supposedly only contains ASCII characters.
-
Field Details
-
header
-
body
-
version
-
-
Constructor Details
-
Message
public Message()
-
-
Method Details
-
read
If the message is HTTP 1.1 but the header has no information about the content length, then an assumption is made that after the body the server will send an EOF. So the body is read till end of the stream. See http://www.ietf.org/rfc/rfc2145.txt- Throws:
IOExceptionEndOfStreamException
-
readBody
- Throws:
IOException
-
discardBody
public void discardBody() -
getBody
-
getBodyAsStream
Probably you want to use
getBodyAsStreamDecoded()instead:Transfer-Encodings (e.g. chunking) have been unapplied, but Content-Encodings (e.g. gzip) have not.
Returns the body as a stream.
Supports streaming: The HTTP message does not have to be completely received yet for this method to return.
- See Also:
-
getBodyAsStreamDecoded
Returns the logical body content.
Any Transfer-Encodings (e.g. chunking) and/or Content-Encodings (e.g. gzip) have been unapplied.
Supports streaming: The HTTP message does not have to be completely received yet for this method to return.
-
getBodyAsStringDecoded
As this method has bad performance, it should not be used in any critical component. (Use
getBodyAsStreamDecoded()instead.)Allocates a new
Stringobject for the whole body (potentially performing charset conversion).Blocks until the body has been fully received.
(... and more bad internal performance)
- Returns:
- the message's body as a Java String.
-
setBody
Sets the body. Does NOT adjust the header fields (Content-Length etc.): UsesetBodyContent(byte[])instead. -
setBodyContent
public void setBodyContent(byte[] content) Sets the body. Also adjusts the header fields (Content-Length, Content-Encoding, Transfer-Encoding). -
createBody
- Throws:
IOException
-
parseStartLine
- Throws:
IOExceptionEndOfStreamException
-
getHeader
-
release
public void release()preserve synchronized keyword, notify method is called -
hasMsgReleased
public boolean hasMsgReleased() -
setHeader
-
write
- Throws:
IOException
-
writeStartLine
The start line supposedly only contains ASCII characters. But sinceHttpUtil.readLine(InputStream)converts the input byte-by-byte to char-by-char, we use ISO-8859-1 for output.- Throws:
IOException
-
getStartLine
-
isHTTP11
public boolean isHTTP11() -
isHTTP10
public boolean isHTTP10() -
getVersion
-
setVersion
-
toString
-
isKeepAlive
public boolean isKeepAlive() -
getErrorMessage
-
setErrorMessage
-
getName
-
isBodyEmpty
- Throws:
IOException
-
shouldNotContainBody
public abstract boolean shouldNotContainBody() -
isImage
public boolean isImage() -
isXML
public boolean isXML() -
isJSON
public boolean isJSON() -
isHTML
public boolean isHTML() -
isCSS
public boolean isCSS() -
isJavaScript
public boolean isJavaScript() -
isGzip
public boolean isGzip() -
isDeflate
public boolean isDeflate() -
getCharset
-
addObserver
-
estimateHeapSize
public int estimateHeapSize() -
createSnapshot
public abstract <T extends Message> T createSnapshot(Runnable bodyUpdatedCallback, BodyCollectingMessageObserver.Strategy strategy, long limit) throws Exception - Throws:
Exception
-
createMessageSnapshot
public <T extends Message> T createMessageSnapshot(T result, Runnable bodyUpdatedCallback, BodyCollectingMessageObserver.Strategy strategy, long limit) -
isReleased
public boolean isReleased() -
setReleased
public void setReleased(boolean released) -
containsObserver
-