Package com.browserup.bup.util
Class HttpMessageContents
- java.lang.Object
-
- com.browserup.bup.util.HttpMessageContents
-
public class HttpMessageContents extends java.lang.ObjectHelper class to wrap the contents of anHttpMessage. Contains convenience methods to extract and manipulate the contents of the wrappedHttpMessage. TODO: Currently this class only wraps FullHttpMessages, since it must modify the Content-Length header; determine if this may be applied to chunked messages as well
-
-
Constructor Summary
Constructors Constructor Description HttpMessageContents(io.netty.handler.codec.http.FullHttpMessage httpMessage)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]getBinaryContents()Retrieves the binary contents of this message.java.nio.charset.CharsetgetCharset()Retrieves the character set of the entity body.java.lang.StringgetContentType()Retrieves the Content-Type header of this message.java.lang.StringgetTextContents()Retrieves the contents of this message as a String, decoded according to the message's Content-Type header.booleanisText()Returns true if this message's Content-Type header indicates that it contains a textual data type.voidsetBinaryContents(byte[] newBinaryContents)Replaces the contents of the wrapped HttpMessage with the specified binary contents.voidsetTextContents(java.lang.String newContents)Replaces the contents of the wrapped HttpMessage with the specified text contents, encoding them in the character set specified by the message's Content-Type header.
-
-
-
Method Detail
-
setTextContents
public void setTextContents(java.lang.String newContents)
Replaces the contents of the wrapped HttpMessage with the specified text contents, encoding them in the character set specified by the message's Content-Type header. Note that this method does not update the Content-Type header, so if the content type will change as a result of this call, the Content-Type header should be updated before calling this method.- Parameters:
newContents- new message contents
-
setBinaryContents
public void setBinaryContents(byte[] newBinaryContents)
Replaces the contents of the wrapped HttpMessage with the specified binary contents. Note that this method does not update the Content-Type header, so if the content type will change as a result of this call, the Content-Type header should be updated before calling this method.- Parameters:
newBinaryContents- new message contents
-
getTextContents
public java.lang.String getTextContents() throws java.nio.charset.UnsupportedCharsetExceptionRetrieves the contents of this message as a String, decoded according to the message's Content-Type header. This method caches the contents, so repeated calls to this method should not incur a penalty; however, modifications to the message contents outside of this class will result in stale data returned from this method.- Returns:
- String representation of the entity body
- Throws:
java.nio.charset.UnsupportedCharsetException- if the character set declared in the message is not supported on this platform
-
getBinaryContents
public byte[] getBinaryContents()
Retrieves the binary contents of this message. This method caches the contents, so repeated calls to this method should not incur a penalty; however, modifications to the message contents outside of this class will result in stale data returned from this method.- Returns:
- binary contents of the entity body
-
getContentType
public java.lang.String getContentType()
Retrieves the Content-Type header of this message. If no Content-Type is present, returns the assumed default Content-Type (seeBrowserUpHttpUtil.UNKNOWN_CONTENT_TYPE).- Returns:
- the message's content type
-
getCharset
public java.nio.charset.Charset getCharset() throws java.nio.charset.UnsupportedCharsetExceptionRetrieves the character set of the entity body. If the Content-Type is not a textual type, this value is meaningless. If no character set is specified, this method will return the default ISO-8859-1 character set. If the Content-Type specifies a character set, but the character set is not supported on this platform, this method throws anUnsupportedCharsetException.- Returns:
- the entity body's character set
- Throws:
java.nio.charset.UnsupportedCharsetException- if the character set declared in the message is not supported on this platform
-
isText
public boolean isText()
Returns true if this message's Content-Type header indicates that it contains a textual data type. SeeBrowserUpHttpUtil.hasTextualContent(String).- Returns:
- true if the Content-Type header is a textual type, otherwise false
-
-