本文整理汇总了Java中javax.ws.rs.core.StreamingOutput类的典型用法代码示例。如果您正苦于以下问题:Java StreamingOutput类的具体用法?Java StreamingOutput怎么用?Java StreamingOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamingOutput类属于javax.ws.rs.core包,在下文中一共展示了StreamingOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConsole
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
/**
* Return a snapshot of the console.
*
* @param subscription
* the valid screenshot of the console.
* @return the valid screenshot of the console.
*/
@GET
@Path("{subscription:\\d+}/console.png")
@Produces("image/png")
public StreamingOutput getConsole(@PathParam("subscription") final int subscription) {
final Map<String, String> parameters = subscriptionResource.getParameters(subscription);
final VCloudCurlProcessor processor = new VCloudCurlProcessor();
authenticate(parameters, processor);
// Get the screen thumbnail
return output -> {
final String url = StringUtils.appendIfMissing(parameters.get(PARAMETER_API), "/") + "vApp/vm-" + parameters.get(PARAMETER_VM)
+ "/screen";
final CurlRequest curlRequest = new CurlRequest("GET", url, null, (request, response) -> {
if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {
// Copy the stream
IOUtils.copy(response.getEntity().getContent(), output);
output.flush();
}
return false;
});
processor.process(curlRequest);
};
}
示例2: getTranslations
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
/**
* Returns Translations of a given {@link Locale}
* @param locale to get the Translation of
* @param request The HTTP-Request - is injected automatically
* @return the translation
*/
@GET
public Response getTranslations(@PathParam("locale") final String locale,
@Context final Request request) {
final Translator translator = TranslatorManager.getTranslator(LocaleUtil.toLocale(locale));
if(translator == null) {
throw new NotFoundException();
}
final File file = translator.getFile();
final Date lastModified = new Date(file.lastModified());
ResponseBuilder respBuilder = request.evaluatePreconditions(lastModified);
if(respBuilder == null) {
respBuilder = Response.ok();
}
return respBuilder.lastModified(lastModified).entity(new StreamingOutput() {
@Override
public void write(final OutputStream output) throws IOException, WebApplicationException {
IOUtils.copy(new FileInputStream(file), output);
}
}).build();
}
示例3: readAllCsv
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@Override
public Response readAllCsv ( final String contextId )
{
final DataContext context = this.provider.getContext ( contextId );
if ( context == null )
{
logger.trace ( "Context '{}' not found", contextId ); //$NON-NLS-1$
throw new WebApplicationException ( Status.NOT_FOUND );
}
final SortedMap<String, DataItemValue> values = context.getAllValues ();
final StreamingOutput out = new StreamingOutput () {
@Override
public void write ( final OutputStream output ) throws IOException, WebApplicationException
{
streamAsCSV ( new PrintWriter ( new OutputStreamWriter ( output, StandardCharsets.UTF_8 ) ), values, ",", "\r\n" ); //$NON-NLS-1$ //$NON-NLS-2$
}
};
return Response.ok ( out ).header ( "Content-Disposition", "attachment; filename=\"data.csv\"" ).build (); //$NON-NLS-1$
}
示例4: getTerraformLog
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
/**
* Get the log of the current or last Terraform execution of a given
* subscription.
*
* @param subscription
* The related subscription.
* @return the streaming {@link Response} with output.
* @throws IOException
* When Terraform content cannot be written.
*/
@GET
@Produces(MediaType.TEXT_HTML)
@Path("{subscription:\\d+}/terraform.log")
public Response getTerraformLog(@PathParam("subscription") final int subscription) throws IOException {
final Subscription entity = subscriptionResource.checkVisibleSubscription(subscription);
final File log = toFile(entity, MAIN_LOG);
// Check there is a log file
if (log.exists()) {
final StreamingOutput so = o -> FileUtils.copyFile(toFile(entity, MAIN_LOG), o);
return Response.ok().entity(so).build();
}
// No log file for now
return Response.status(Status.NOT_FOUND).build();
}
示例5: generateBinaryDataResponse
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
private Response generateBinaryDataResponse(JobId jobId, Optional<BinaryData> maybeBinaryData) {
if (maybeBinaryData.isPresent()) {
final BinaryData binaryData = maybeBinaryData.get();
final StreamingOutput body = outputStream -> {
IOUtils.copyLarge(binaryData.getData(), outputStream);
binaryData.getData().close();
};
final Response.ResponseBuilder b =
Response.ok(body, binaryData.getMimeType())
.header("Content-Length", binaryData.getSizeOf());
if (binaryData.getSizeOf() > Constants.MAX_JOB_OUTPUT_SIZE_IN_BYTES_BEFORE_DISABLING_COMPRESSION)
b.header("Content-Encoding", "identity");
return b.build();
} else {
return Response.status(404).build();
}
}
示例6: renderTemplate2Response
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
/**
* Generate a {@link Response.ResponseBuilder} instance
* and render the excel template with the specified data to its output stream.
*
* @param template the excel template, can be xlsx or xls format
* @param data the data
* @param filename the download filename of the response
* @return the instance of {@link Response.ResponseBuilder} with the excel data
* @throws RuntimeException if has IOException or UnsupportedEncodingException inner
*/
public static Response.ResponseBuilder renderTemplate2Response(InputStream template, Map<String, Object> data,
String filename) {
StreamingOutput stream = (OutputStream output) -> {
// Convert to jxls Context
Context context = convert2Context(data);
// Add default functions
addDefault(context);
// render
renderByJxls(template, output, context);
};
// create response
Response.ResponseBuilder builder = Response.ok(stream);
if (filename != null) {
try {
builder.header("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
return builder;
}
示例7: downloadLobFile
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
/**
* Bench the get picture file.
*
* @return the JAX-RS stream.
*/
@GET
@Path("picture.png")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@OnNullReturn404
public StreamingOutput downloadLobFile() {
log.info("Picture download is requested");
final byte[] firstAvailableLob = jpaDao.getLastAvailableLob();
if (firstAvailableLob.length == 0) {
return null;
}
return output -> {
try {
IOUtils.write(firstAvailableLob, output);
} catch (final IOException e) {
throw new IllegalStateException("Unable to write the LOB data", e);
}
};
}
示例8: testDownloadDataBlobError
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testDownloadDataBlobError() throws Exception {
final URL jarLocation = getBlobFile();
InputStream openStream = null;
try {
// Get the JAR input
openStream = jarLocation.openStream();
// Proceed to the test
resource.prepareData(openStream, 1);
final StreamingOutput downloadLobFile = resource.downloadLobFile();
final OutputStream output = Mockito.mock(OutputStream.class);
Mockito.doThrow(new IOException()).when(output).write(ArgumentMatchers.any(byte[].class));
downloadLobFile.write(output);
} finally {
IOUtils.closeQuietly(openStream);
}
}
示例9: testDownloadDataBlob
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@Test
public void testDownloadDataBlob() throws Exception {
final URL jarLocation = getBlobFile();
InputStream openStream = null;
try {
// Get the JAR input
openStream = jarLocation.openStream();
// Proceed to the test
resource.prepareData(openStream, 1);
final StreamingOutput downloadLobFile = resource.downloadLobFile();
final ByteArrayOutputStream output = new ByteArrayOutputStream();
downloadLobFile.write(output);
org.junit.Assert.assertTrue(output.toByteArray().length > 3000000);
} finally {
IOUtils.closeQuietly(openStream);
}
}
示例10: downloadData
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@POST
@Path("download")
@Consumes(MediaType.APPLICATION_JSON)
public Response downloadData(@PathParam("jobId") JobId jobId)
throws IOException, UserNotFoundException, JobResourceNotFoundException {
final DownloadDataResponse response;
try {
response = supportService.downloadSupportRequest(context.getUserPrincipal().getName(), jobId);
} catch (JobNotFoundException e) {
throw JobResourceNotFoundException.fromJobNotFoundException(e);
}
final StreamingOutput streamingOutput = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
IOUtils.copyBytes(response.getInput(), output, 4096, true);
}
};
return Response.ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM)
.header("Content-Disposition", "attachment; filename=\"" + response.getFileName() + "\"").build();
}
示例11: getStatusHistory
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@Test
public void getStatusHistory() throws Exception {
final int subscription = getSubscription("MDA");
final StreamingOutput csv = (StreamingOutput) resource.getStatusHistory(subscription, "file1").getEntity();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
csv.write(out);
final BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray()), "cp1252"));
final String header = inputStreamReader.readLine();
Assert.assertEquals("issueid;key;author;from;to;fromText;toText;date;dateTimestamp", header);
String lastLine = inputStreamReader.readLine();
Assert.assertEquals("11432;MDA-1;fdaugan;;1;;OPEN;2009/03/23 15:26:43;1237818403000", lastLine);
lastLine = inputStreamReader.readLine();
Assert.assertEquals("11437;MDA-4;xsintive;;1;;OPEN;2009/03/23 16:23:31;1237821811000", lastLine);
lastLine = inputStreamReader.readLine();
lastLine = inputStreamReader.readLine();
lastLine = inputStreamReader.readLine();
lastLine = inputStreamReader.readLine();
Assert.assertEquals("11535;MDA-8;challer;;1;;OPEN;2009/04/01 14:20:29;1238588429000", lastLine);
lastLine = inputStreamReader.readLine();
lastLine = inputStreamReader.readLine();
lastLine = inputStreamReader.readLine();
Assert.assertEquals("11535;MDA-8;fdaugan;1;10024;OPEN;ASSIGNED;2009/04/09 09:45:16;1239263116000", lastLine);
lastLine = inputStreamReader.readLine();
Assert.assertEquals("11535;MDA-8;fdaugan;10024;3;ASSIGNED;IN PROGRESS;2009/04/09 09:45:30;1239263130000", lastLine);
}
示例12: listJSON
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@GET()
@Produces(MediaType.APPLICATION_JSON)
@MCRRestrictedAccess(MCRJobQueuePermission.class)
public Response listJSON() {
try {
Queues queuesEntity = new Queues();
queuesEntity.addAll(
MCRJobQueue.INSTANCES.keySet().stream().map(Queue::new).collect(Collectors.toList()));
return Response.ok().status(Response.Status.OK).entity(queuesEntity)
.build();
} catch (Exception e) {
final StreamingOutput so = (OutputStream os) -> e
.printStackTrace(new PrintStream(os, false, StandardCharsets.UTF_8.name()));
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(so).build();
}
}
示例13: listXML
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@GET()
@Produces(MediaType.APPLICATION_XML)
@MCRRestrictedAccess(MCRJobQueuePermission.class)
public Response listXML() {
try {
Queues queuesEntity = new Queues();
queuesEntity.addAll(
MCRJobQueue.INSTANCES.keySet().stream().map(Queue::new).collect(Collectors.toList()));
return Response.ok().status(Response.Status.OK).entity(toJSON(queuesEntity))
.build();
} catch (Exception e) {
final StreamingOutput so = (OutputStream os) -> e
.printStackTrace(new PrintStream(os, false, StandardCharsets.UTF_8.name()));
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(so).build();
}
}
示例14: getArtifactStream
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
@Override
public StreamingOutput getArtifactStream(final IndexArtifact artifact, final String filename)
{
Path streamPath = fs.getPath(getPath() + artifact.getLocation() + "/" + filename);
if (Files.isReadable(streamPath))
{
return new StreamingOutput()
{
public void write(OutputStream os) throws IOException, WebApplicationException
{
FileInputStream fis = new FileInputStream(streamPath.toString());
ByteStreams.copy(fis, os);
fis.close();
}
};
}
else
{
throw new NotFoundException();
}
}
示例15: getResponseEntityClass
import javax.ws.rs.core.StreamingOutput; //导入依赖的package包/类
/**
* <p>getResponseEntityClass.</p>
*
* @param mimeType a {@link org.aml.apimodel.MimeType} object.
* @return a {@link com.sun.codemodel.JType} object.
* @throws java.io.IOException if any.
*/
public JType getResponseEntityClass(final MimeType mimeType) throws IOException
{
final JClass schemaClass = getSchemaClass(mimeType);
if (schemaClass != null)
{
return schemaClass;
}
else if (startsWith(mimeType.getType(), "text/"))
{
return getGeneratorType(String.class);
}
else
{
// fallback to a streaming output
return getGeneratorType(StreamingOutput.class);
}
}