@GET
@Path("{id : \\d+}")
@Produces("application/xml")
public StreamingOutput getCustomer(@PathParam("id") int id)
{
final Customer customer = customerDB.get(id);
if (customer == null)
{
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return new StreamingOutput()
{
public void write(OutputStream outputStream) throws IOException, WebApplicationException
{
outputCustomer(outputStream, customer);
}
};
}
java类javax.ws.rs.core.StreamingOutput的实例源码
CustomerResource.java 文件源码
项目:resteasy-examples
阅读 25
收藏 0
点赞 0
评论 0
CustomerResource.java 文件源码
项目:resteasy-examples
阅读 23
收藏 0
点赞 0
评论 0
@GET
@Path("{id}")
@Produces("application/xml")
public StreamingOutput getCustomer(@PathParam("id") int id)
{
final Customer customer = customerDB.get(id);
if (customer == null)
{
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return new StreamingOutput()
{
public void write(OutputStream outputStream) throws IOException, WebApplicationException
{
outputCustomer(outputStream, customer);
}
};
}
AuditService.java 文件源码
项目:codenvy
阅读 21
收藏 0
点赞 0
评论 0
@GET
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Generate audit log")
@ApiResponses(
value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 500, message = "Server error")
}
)
public Response downloadReport() throws ServerException, ConflictException, IOException {
java.nio.file.Path report = auditManager.generateAuditReport();
StreamingOutput stream =
outputStream -> {
try {
copy(report, outputStream);
} finally {
auditManager.deleteReportDirectory(report);
}
};
return Response.ok(stream, MediaType.TEXT_PLAIN)
.header("Content-Length", String.valueOf(Files.size(report)))
.header("Content-Disposition", "attachment; filename=" + report.getFileName().toString())
.build();
}
CustomerResource.java 文件源码
项目:resteasy-examples
阅读 20
收藏 0
点赞 0
评论 0
@GET
@Path("{id : \\d+}")
@Produces("application/xml")
public StreamingOutput getCustomer(@PathParam("id") int id)
{
final Customer customer = customerDB.get(id);
if (customer == null)
{
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return new StreamingOutput()
{
public void write(OutputStream outputStream) throws IOException, WebApplicationException
{
outputCustomer(outputStream, customer);
}
};
}
FirstLastCustomerResource.java 文件源码
项目:resteasy-examples
阅读 20
收藏 0
点赞 0
评论 0
@GET
@Path("{first}-{last}")
@Produces("application/xml")
public StreamingOutput getCustomer(@PathParam("first") String firstName,
@PathParam("last") String lastName)
{
final Customer customer = customerDB.get(firstName + "-" + lastName);
if (customer == null)
{
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return new StreamingOutput()
{
public void write(OutputStream outputStream) throws IOException, WebApplicationException
{
outputCustomer(outputStream, customer);
}
};
}
CustomerResource.java 文件源码
项目:resteasy-examples
阅读 19
收藏 0
点赞 0
评论 0
@GET
@Path("{id}")
@Produces("application/xml")
public StreamingOutput getCustomer(@PathParam("id") int id)
{
final Customer customer = customerDB.get(id);
if (customer == null)
{
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
return new StreamingOutput()
{
public void write(OutputStream outputStream) throws IOException, WebApplicationException
{
outputCustomer(outputStream, customer);
}
};
}
FileServices.java 文件源码
项目:step
阅读 14
收藏 0
点赞 0
评论 0
@GET
@Secured
@Path("/{id}")
public Response downloadFile(@PathParam("id") String id) {
File file = attachmentManager.getFileById(id);
StreamingOutput fileStream = new StreamingOutput() {
@Override
public void write(java.io.OutputStream output) throws IOException {
java.nio.file.Path path = file.toPath();
byte[] data = Files.readAllBytes(path);
output.write(data);
output.flush();
}
};
return Response.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename = "+file.getName()).build();
}
TestFilterServlet.java 文件源码
项目:fili
阅读 19
收藏 0
点赞 0
评论 0
/**
* An endpoint at /fail.
*
* @param uriInfo The URI info of the request
* @param asyncResponse The response to respond to
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/fail")
public void getFail(@Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
// Process stream
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException {
try {
Thread.sleep(100);
} catch (InterruptedException ignore) {
// Ignore
}
throw new IOException();
}
};
// pass stream handler as response
javax.ws.rs.core.Response rsp = javax.ws.rs.core.Response.ok(stream).build();
asyncResponse.resume(rsp);
}
JavaRepository.java 文件源码
项目:hangar
阅读 15
收藏 0
点赞 0
评论 0
/**
* This version is different as we need to re-write the filename with the
* timestamp for the latest version.
*
* @param key
* IndexKey to find the Artifact in the Index
* @param filename
* Filename from the request
* @return StreamingOutput from the Storage Layer
*/
protected StreamingOutput getSnapshotArtifact(JavaIndexKey key, String filename)
{
logger.info("[Downloading Snapshot] " + key);
try
{
if (getIndex().isArtifact(key))
{
JavaIndexArtifact ia = (JavaIndexArtifact) getIndex().getArtifact(key);
String snapshotFilename = filename.replace(key.getVersion(), ia.getSnapshotVersion());
return getStorage().getArtifactStream(ia, snapshotFilename);
}
else
{
throw new NotFoundException();
}
}
catch (IndexException ie)
{
throw new InternalServerErrorException();
}
}
GsonMessageBodyProvider.java 文件源码
项目:GitHub
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void writeTo(
Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream)
throws IOException,
WebApplicationException {
// Special case of unsupported type, where surrounding framework
// may have, mistakengly, chosen this provider based on media type, but when
// response will be streamed using StreamingOutput or is already prepared using
// in the form of CharSequence
if (t instanceof StreamingOutput) {
((StreamingOutput) t).write(entityStream);
return;
}
if (t instanceof CharSequence) {
// UTF-8 used because it should be considered default encoding for the JSON-family
// of media types
OutputStreamWriter writer = new OutputStreamWriter(entityStream, StandardCharsets.UTF_8);
writer.append((CharSequence) t);
writer.flush();
return;
}
// Standard way of handling writing using gson
try {
streamer.write(gson, genericType, t, entityStream);
} catch (IOException ex) {
exceptionHandler.onWrite(gson, ex);
throw ex;
}
}