public class ServerResponse
extends java.lang.Object
Constructor and Description |
---|
ServerResponse(int responseCode) |
ServerResponse(int responseCode,
java.lang.String responseMessage) |
Modifier and Type | Method and Description |
---|---|
void |
addAllHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerMap)
Add all name/values from the given map.
|
void |
addHeader(java.lang.String name,
java.lang.String value)
Add a header value to the header with the given name.
|
void |
appendContent(byte[] data)
Appends the given bytes to the content.
|
void |
appendContent(java.io.InputStream inStream)
Appends the bytes from the given stream to the content.
|
void |
appendContent(java.lang.String text)
Appends the given text to the content using the currently defined
character encoding.
|
protected java.nio.charset.Charset |
asCharset(java.lang.String contentType) |
protected MediaType |
asMediaType(java.lang.String contentType) |
java.nio.charset.Charset |
getCharset()
Returns the character encoding defined in the Content-Type header
or null if it is not set.
|
protected java.nio.charset.Charset |
getCharsetEncoding() |
protected java.io.ByteArrayOutputStream |
getContentBuffer() |
byte[] |
getContentData()
Returns the content data or null if no content is available.
|
protected java.io.ByteArrayOutputStream |
getContentDataStream() |
int |
getContentLength() |
MediaType |
getContentMediaType()
Returns the media type specified in the "Content-Type" header
of null if not set.
|
java.io.Reader |
getContentReader()
Returns the content data as reader (with correct char encoding) or null
if no content is available.
|
java.lang.String |
getContentText()
Returns the content data as text (with correct char encoding) or null
if no content is available.
|
protected java.lang.String |
getContentTypeHeader()
Returns the "Content-Type" header unparsed.
|
protected java.nio.charset.Charset |
getDefaultCharset() |
java.lang.String |
getHeader(java.lang.String name)
Returns a single value (the first) of the header with the given name.
|
protected Headers |
getHeaders() |
protected Logger |
getLogger() |
protected int |
getReadBufferSize() |
int |
getResponseCode() |
java.lang.String |
getResponseMessage() |
boolean |
hasContentData() |
boolean |
isCodeIn(int... codes)
Returns true if the response has a status code that equals
one of the given codes.
|
boolean |
isCodeInRange(int fromCode,
int toCode)
Returns true if the response has a status code that is in the specified
code range (fromCode and toCode both included).
|
boolean |
isOk()
Returns true if the response has returned with the OK status code (i.e.
|
void |
removeHeader(java.lang.String name)
Returns the header with the given name and all its associated values.
|
void |
setCharEncoding(java.lang.String charEncoding)
Sets the character encoding to be used on the received content when it gets
converted to text.
|
void |
setCharset(java.nio.charset.Charset charset)
Sets the character encoding in the Content-Type header
or removes it if the given parameter is null.
|
protected void |
setContentDataStream(java.io.ByteArrayOutputStream bodyData) |
void |
setContentMediaType(MediaType mediaType)
Sets the media type in the Content-Type header
or removes the entire header if the given parameter is null.
|
void |
setContentType(MediaType mediaType,
java.nio.charset.Charset charset)
Sets the "Content-Type" header.
|
protected void |
setContentTypeHeader(MediaType mediaType,
java.nio.charset.Charset charset)
Sets the "Content-Type" header.
|
void |
setHeader(java.lang.String name,
java.lang.String value)
A a header with a single value.
|
void |
setResponseMessage(java.lang.String responseMessage) |
public ServerResponse(int responseCode)
public ServerResponse(int responseCode, java.lang.String responseMessage)
public int getResponseCode()
public java.lang.String getResponseMessage()
public void setResponseMessage(java.lang.String responseMessage)
public void setCharEncoding(java.lang.String charEncoding)
charEncoding
- The encoding name (e.g. "UTF-8"). If null the default HTTP encoding will be set.public boolean isOk()
public boolean isCodeIn(int... codes)
public boolean isCodeInRange(int fromCode, int toCode)
public void setContentType(MediaType mediaType, java.nio.charset.Charset charset)
mediaType
- The media type to set. If null the header will be removed.charset
- The charset to be set. If null it will be ignored.public java.nio.charset.Charset getCharset()
public void setCharset(java.nio.charset.Charset charset)
java.lang.IllegalStateException
- If no media type is specified yet.public MediaType getContentMediaType()
public void setContentMediaType(MediaType mediaType)
public boolean hasContentData()
public int getContentLength()
public void appendContent(byte[] data)
public void appendContent(java.io.InputStream inStream) throws java.io.IOException
inStream
- The stream from which to read the bytes (must not be null).java.io.IOException
- If any problem with the input stream occurs.public void appendContent(java.lang.String text)
text
- The text to be appended (null will be ignored).java.lang.IllegalStateException
- If no encoding is set.public byte[] getContentData()
public java.io.Reader getContentReader()
public java.lang.String getContentText()
public void addAllHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerMap)
headerMap
- The header names and values to be a added (if null, nothing will be done).public void addHeader(java.lang.String name, java.lang.String value)
public void setHeader(java.lang.String name, java.lang.String value)
public java.lang.String getHeader(java.lang.String name)
public void removeHeader(java.lang.String name)
protected MediaType asMediaType(java.lang.String contentType)
protected java.nio.charset.Charset asCharset(java.lang.String contentType)
protected java.lang.String getContentTypeHeader()
protected void setContentTypeHeader(MediaType mediaType, java.nio.charset.Charset charset)
protected java.nio.charset.Charset getCharsetEncoding()
protected java.nio.charset.Charset getDefaultCharset()
protected java.io.ByteArrayOutputStream getContentBuffer()
protected java.io.ByteArrayOutputStream getContentDataStream()
protected void setContentDataStream(java.io.ByteArrayOutputStream bodyData)
protected Headers getHeaders()
protected int getReadBufferSize()
protected Logger getLogger()