Replace StreamingResult with BinaryResult

The BinaryResult type allows RestApiViews to return an unknown
content length with no gzip compression applied. This is the same
as what a StreamingResult allowed, but uses less code by reusing
the existing BinaryResult support.

Change-Id: Ieefada279fc790ea9542dc386bcab1247eab4365
diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/StreamingResponse.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/StreamingResponse.java
deleted file mode 100644
index b2fb901..0000000
--- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/StreamingResponse.java
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (C) 2013 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.gerrit.extensions.restapi;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public interface StreamingResponse {
-  public String getContentType();
-  public void stream(OutputStream out) throws IOException;
-}
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
index fa1e902..4d82dd5 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
@@ -65,7 +65,6 @@
 import com.google.gerrit.extensions.restapi.RestReadView;
 import com.google.gerrit.extensions.restapi.RestResource;
 import com.google.gerrit.extensions.restapi.RestView;
-import com.google.gerrit.extensions.restapi.StreamingResponse;
 import com.google.gerrit.extensions.restapi.TopLevelResource;
 import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
 import com.google.gerrit.httpd.WebSession;
@@ -307,11 +306,7 @@
       }
       res.setStatus(status);
 
-      if (result instanceof StreamingResponse) {
-        StreamingResponse r = (StreamingResponse) result;
-        res.setContentType(r.getContentType());
-        r.stream(res.getOutputStream());
-      } else if (result != Response.none()) {
+      if (result != Response.none()) {
         result = Response.unwrap(result);
         if (result instanceof BinaryResult) {
           replyBinaryResult(req, res, (BinaryResult) result);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java
index d4d923e..5b19ff0 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java
@@ -18,8 +18,8 @@
 import com.google.gerrit.common.data.GarbageCollectionResult;
 import com.google.gerrit.common.data.GlobalCapability;
 import com.google.gerrit.extensions.annotations.RequiresCapability;
+import com.google.gerrit.extensions.restapi.BinaryResult;
 import com.google.gerrit.extensions.restapi.RestModifyView;
-import com.google.gerrit.extensions.restapi.StreamingResponse;
 import com.google.gerrit.server.git.GarbageCollection;
 import com.google.gerrit.server.project.GarbageCollect.Input;
 import com.google.inject.Inject;
@@ -43,15 +43,10 @@
   }
 
   @Override
-  public StreamingResponse apply(final ProjectResource rsrc, Input input) {
-    return new StreamingResponse() {
+  public BinaryResult apply(final ProjectResource rsrc, Input input) {
+    return new BinaryResult() {
       @Override
-      public String getContentType() {
-        return "text/plain;charset=UTF-8";
-      }
-
-      @Override
-      public void stream(OutputStream out) throws IOException {
+      public void writeTo(OutputStream out) throws IOException {
         PrintWriter writer = new PrintWriter(
             new OutputStreamWriter(out, Charsets.UTF_8)) {
           @Override
@@ -88,6 +83,7 @@
           writer.flush();
         }
       }
-    };
+    }.setContentType("text/plain; charset=UTF-8")
+     .disableGzip();
   }
 }