Class BinaryResult
- java.lang.Object
- 
- com.google.gerrit.extensions.restapi.BinaryResult
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 
 public abstract class BinaryResult extends Object implements Closeable Wrapper around a non-JSON result from aRestView.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[]orInputSteam.
- 
- 
Constructor SummaryConstructors Constructor Description BinaryResult()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringasString()Return a copy of the result as a String.BinaryResultbase64()Wrap the binary data in base64 encoding.booleancanGzip()Returns true if this result can be gzip compressed to clients.voidclose()Close the result and release any resources it holds.static BinaryResultcreate(byte[] data)Produce anapplication/octet-streamresult from a byte array.static BinaryResultcreate(InputStream data)Produce anapplication/octet-streamof unknown length by copying the InputStream until EOF.static BinaryResultcreate(String data)Produce a UTF-8 encoded result from a string.BinaryResultdisableGzip()Disable gzip compression for already compressed responses.StringgetAttachmentName()Get the attachment file name; null if not set.CharsetgetCharacterEncoding()Get the character encoding; null if not known.longgetContentLength()Returns length in bytes of the result; -1 if not known.StringgetContentType()Returns the MIME type of the result, for HTTP clients.booleanisBase64()Returns true if the result must be base64 encoded.BinaryResultsetAttachmentName(String attachmentName)Set the attachment file name and returnthis.BinaryResultsetCharacterEncoding(Charset encoding)Set the character set used to encode text data and returnthis.BinaryResultsetContentLength(long len)Set the content length of the result; -1 if not known.BinaryResultsetContentType(String contentType)Set the MIME type of the result, and returnthis.StringtoString()abstract voidwriteTo(OutputStream os)Write or copy the result onto the specified output stream.
 
- 
- 
- 
Method Detail- 
createpublic static BinaryResult create(String data) Produce a UTF-8 encoded result from a string.
 - 
createpublic static BinaryResult create(byte[] data) Produce anapplication/octet-streamresult from a byte array.
 - 
createpublic static BinaryResult create(InputStream data) Produce anapplication/octet-streamof unknown length by copying the InputStream until EOF. The server glue will automatically close this stream when copying is complete.
 - 
getContentTypepublic String getContentType() Returns the MIME type of the result, for HTTP clients.
 - 
setContentTypepublic BinaryResult setContentType(String contentType) Set the MIME type of the result, and returnthis.
 - 
getCharacterEncodingpublic Charset getCharacterEncoding() Get the character encoding; null if not known.
 - 
setCharacterEncodingpublic BinaryResult setCharacterEncoding(Charset encoding) Set the character set used to encode text data and returnthis.
 - 
getAttachmentNamepublic String getAttachmentName() Get the attachment file name; null if not set.
 - 
setAttachmentNamepublic BinaryResult setAttachmentName(String attachmentName) Set the attachment file name and returnthis.
 - 
getContentLengthpublic long getContentLength() Returns length in bytes of the result; -1 if not known.
 - 
setContentLengthpublic BinaryResult setContentLength(long len) Set the content length of the result; -1 if not known.
 - 
canGzippublic boolean canGzip() Returns true if this result can be gzip compressed to clients.
 - 
disableGzippublic BinaryResult disableGzip() Disable gzip compression for already compressed responses.
 - 
isBase64public boolean isBase64() Returns true if the result must be base64 encoded.
 - 
base64public BinaryResult base64() Wrap the binary data in base64 encoding.
 - 
writeTopublic abstract void writeTo(OutputStream os) throws IOException Write or copy the result onto the specified output stream.- Parameters:
- os- stream to write result data onto. This stream will be closed by the caller after this method returns.
- Throws:
- IOException- if the data cannot be produced, or the OutputStream- osthrows any IOException during a write or flush call.
 
 - 
asStringpublic String asString() throws IOException Return a copy of the result as a String.The default version of this method copies the result into a temporary byte array and then tries to decode it using the configured encoding. - Returns:
- string version of the result.
- Throws:
- IOException- if the data cannot be produced or could not be decoded to a String.
 
 - 
closepublic void close() throws IOExceptionClose the result and release any resources it holds.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- IOException
 
 
- 
 
-