Move base64 response encoding into BinaryResult

Make it easy for any RestApiView to return binary data within a
base64 wrapper by marking a BinaryResult with base64() before it
is given to RestApiServlet. The servlet will process the base64
wrapping before gzip encoding, which may save on transfer cost.

Change-Id: I5ed7b8cb2b034b60654cc2574e627159b11a4f27
This commit is contained in:
Shawn Pearce
2013-05-09 11:54:17 -07:00
parent a523bd8c00
commit 45b0ed1633
3 changed files with 60 additions and 19 deletions

View File

@@ -61,6 +61,7 @@ public abstract class BinaryResult implements Closeable {
private String characterEncoding;
private long contentLength = -1;
private boolean gzip = true;
private boolean base64 = false;
/** @return the MIME type of the result, for HTTP clients. */
public String getContentType() {
@@ -110,6 +111,17 @@ public abstract class BinaryResult implements Closeable {
return this;
}
/** @return true if the result must be base64 encoded. */
public boolean isBase64() {
return base64;
}
/** Wrap the binary data in base64 encoding. */
public BinaryResult base64() {
base64 = true;
return this;
}
/**
* Write or copy the result onto the specified output stream.
*