public abstract class BinaryResult
extends java.lang.Object
implements java.io.Closeable
RestView
.
Views may return this type to signal they want the server glue to write raw data to the
client, instead of attempting automatic conversion to JSON. The create form is overloaded to
handle plain text from a String, or binary data from a byte[]
or InputSteam
.
Constructor and Description |
---|
BinaryResult() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
asString()
Return a copy of the result as a String.
|
BinaryResult |
base64()
Wrap the binary data in base64 encoding.
|
boolean |
canGzip() |
void |
close()
Close the result and release any resources it holds.
|
static BinaryResult |
create(byte[] data)
Produce an
application/octet-stream result from a byte array. |
static BinaryResult |
create(java.io.InputStream data)
Produce an
application/octet-stream of unknown length by copying the InputStream until
EOF. |
static BinaryResult |
create(java.lang.String data)
Produce a UTF-8 encoded result from a string.
|
BinaryResult |
disableGzip()
Disable gzip compression for already compressed responses.
|
java.lang.String |
getAttachmentName()
Get the attachment file name; null if not set.
|
java.nio.charset.Charset |
getCharacterEncoding()
Get the character encoding; null if not known.
|
long |
getContentLength() |
java.lang.String |
getContentType() |
boolean |
isBase64() |
BinaryResult |
setAttachmentName(java.lang.String attachmentName)
Set the attachment file name and return
this . |
BinaryResult |
setCharacterEncoding(java.nio.charset.Charset encoding)
Set the character set used to encode text data and return
this . |
BinaryResult |
setContentLength(long len)
Set the content length of the result; -1 if not known.
|
BinaryResult |
setContentType(java.lang.String contentType)
Set the MIME type of the result, and return
this . |
java.lang.String |
toString() |
abstract void |
writeTo(java.io.OutputStream os)
Write or copy the result onto the specified output stream.
|
public static BinaryResult create(java.lang.String data)
public static BinaryResult create(byte[] data)
application/octet-stream
result from a byte array.public static BinaryResult create(java.io.InputStream data)
application/octet-stream
of unknown length by copying the InputStream until
EOF. The server glue will automatically close this stream when copying is complete.public java.lang.String getContentType()
public BinaryResult setContentType(java.lang.String contentType)
this
.public java.nio.charset.Charset getCharacterEncoding()
public BinaryResult setCharacterEncoding(java.nio.charset.Charset encoding)
this
.public java.lang.String getAttachmentName()
public BinaryResult setAttachmentName(java.lang.String attachmentName)
this
.public long getContentLength()
public BinaryResult setContentLength(long len)
public boolean canGzip()
public BinaryResult disableGzip()
public boolean isBase64()
public BinaryResult base64()
public abstract void writeTo(java.io.OutputStream os) throws java.io.IOException
os
- stream to write result data onto. This stream will be closed by the caller after this
method returns.java.io.IOException
- if the data cannot be produced, or the OutputStream os
throws any
IOException during a write or flush call.public java.lang.String asString() throws java.io.IOException
The default version of this method copies the result into a temporary byte array and then tries to decode it using the configured encoding.
java.io.IOException
- if the data cannot be produced or could not be decoded to a String.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object