Merge "Replace StreamingResult with BinaryResult"
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
@@ -65,7 +65,6 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
|
|||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.extensions.restapi.RestResource;
|
import com.google.gerrit.extensions.restapi.RestResource;
|
||||||
import com.google.gerrit.extensions.restapi.RestView;
|
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.TopLevelResource;
|
||||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||||
import com.google.gerrit.httpd.WebSession;
|
import com.google.gerrit.httpd.WebSession;
|
||||||
@@ -307,11 +306,7 @@ public class RestApiServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
res.setStatus(status);
|
res.setStatus(status);
|
||||||
|
|
||||||
if (result instanceof StreamingResponse) {
|
if (result != Response.none()) {
|
||||||
StreamingResponse r = (StreamingResponse) result;
|
|
||||||
res.setContentType(r.getContentType());
|
|
||||||
r.stream(res.getOutputStream());
|
|
||||||
} else if (result != Response.none()) {
|
|
||||||
result = Response.unwrap(result);
|
result = Response.unwrap(result);
|
||||||
if (result instanceof BinaryResult) {
|
if (result instanceof BinaryResult) {
|
||||||
replyBinaryResult(req, res, (BinaryResult) result);
|
replyBinaryResult(req, res, (BinaryResult) result);
|
||||||
|
@@ -18,8 +18,8 @@ import com.google.common.base.Charsets;
|
|||||||
import com.google.gerrit.common.data.GarbageCollectionResult;
|
import com.google.gerrit.common.data.GarbageCollectionResult;
|
||||||
import com.google.gerrit.common.data.GlobalCapability;
|
import com.google.gerrit.common.data.GlobalCapability;
|
||||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
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.RestModifyView;
|
||||||
import com.google.gerrit.extensions.restapi.StreamingResponse;
|
|
||||||
import com.google.gerrit.server.git.GarbageCollection;
|
import com.google.gerrit.server.git.GarbageCollection;
|
||||||
import com.google.gerrit.server.project.GarbageCollect.Input;
|
import com.google.gerrit.server.project.GarbageCollect.Input;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -43,15 +43,10 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamingResponse apply(final ProjectResource rsrc, Input input) {
|
public BinaryResult apply(final ProjectResource rsrc, Input input) {
|
||||||
return new StreamingResponse() {
|
return new BinaryResult() {
|
||||||
@Override
|
@Override
|
||||||
public String getContentType() {
|
public void writeTo(OutputStream out) throws IOException {
|
||||||
return "text/plain;charset=UTF-8";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stream(OutputStream out) throws IOException {
|
|
||||||
PrintWriter writer = new PrintWriter(
|
PrintWriter writer = new PrintWriter(
|
||||||
new OutputStreamWriter(out, Charsets.UTF_8)) {
|
new OutputStreamWriter(out, Charsets.UTF_8)) {
|
||||||
@Override
|
@Override
|
||||||
@@ -88,6 +83,7 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input> {
|
|||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}.setContentType("text/plain; charset=UTF-8")
|
||||||
|
.disableGzip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user