Search in sources :

Example 26 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project pentaho-platform by pentaho.

the class FileService method systemBackup.

public DownloadFileWrapper systemBackup(String userAgent) throws IOException, ExportException {
    if (doCanAdminister()) {
        String originalFileName;
        String encodedFileName;
        originalFileName = "SystemBackup.zip";
        encodedFileName = makeEncodedFileName(originalFileName);
        StreamingOutput streamingOutput = getBackupStream();
        final String attachment = HttpMimeTypeListener.buildContentDispositionValue(originalFileName, true);
        return new DownloadFileWrapper(streamingOutput, attachment, encodedFileName);
    } else {
        throw new SecurityException();
    }
}
Also used : StreamingOutput(javax.ws.rs.core.StreamingOutput) GeneralSecurityException(java.security.GeneralSecurityException)

Example 27 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project pentaho-platform by pentaho.

the class FileService method getBackupStream.

private StreamingOutput getBackupStream() throws IOException, ExportException {
    File zipFile = getBackupExporter().performExport();
    final FileInputStream inputStream = new FileInputStream(zipFile);
    return new StreamingOutput() {

        @Override
        public void write(OutputStream output) throws IOException {
            IOUtils.copy(inputStream, output);
        }
    };
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryFileOutputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) FileInputStream(java.io.FileInputStream)

Example 28 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project syncope by apache.

the class RoleServiceImpl method getConsoleLayoutInfo.

@Override
public Response getConsoleLayoutInfo(final String key) {
    String template = logic.getConsoleLayoutInfo(key);
    StreamingOutput sout = (os) -> os.write(template.getBytes());
    return Response.ok(sout).type(MediaType.APPLICATION_JSON_TYPE).build();
}
Also used : RoleService(org.apache.syncope.common.rest.api.service.RoleService) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) StreamingOutput(javax.ws.rs.core.StreamingOutput) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) RoleTO(org.apache.syncope.common.lib.to.RoleTO) Response(javax.ws.rs.core.Response) Service(org.springframework.stereotype.Service) RoleLogic(org.apache.syncope.core.logic.RoleLogic) URI(java.net.URI) RESTHeaders(org.apache.syncope.common.rest.api.RESTHeaders) InputStream(java.io.InputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 29 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project syncope by apache.

the class MailTemplateServiceImpl method getFormat.

@Override
public Response getFormat(final String key, final MailTemplateFormat format) {
    String template = logic.getFormat(key, format);
    StreamingOutput sout = (os) -> os.write(template.getBytes());
    return Response.ok(sout).type(format.getMediaType()).build();
}
Also used : MailTemplateLogic(org.apache.syncope.core.logic.MailTemplateLogic) MailTemplateService(org.apache.syncope.common.rest.api.service.MailTemplateService) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) StreamingOutput(javax.ws.rs.core.StreamingOutput) MailTemplateFormat(org.apache.syncope.common.lib.types.MailTemplateFormat) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) Service(org.springframework.stereotype.Service) URI(java.net.URI) RESTHeaders(org.apache.syncope.common.rest.api.RESTHeaders) InputStream(java.io.InputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 30 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project ANNIS by korpling.

the class QueryServiceImpl method findRaw.

private StreamingOutput findRaw(final QueryData data, final String rawCorpusNames, final String query) throws IOException {
    return new StreamingOutput() {

        @Override
        public void write(OutputStream output) throws IOException, WebApplicationException {
            long start = new Date().getTime();
            queryDao.find(data, output);
            long end = new Date().getTime();
            logQuery("FIND", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start);
        }
    };
}
Also used : OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) Date(java.util.Date)

Aggregations

StreamingOutput (javax.ws.rs.core.StreamingOutput)191 OutputStream (java.io.OutputStream)85 Response (javax.ws.rs.core.Response)76 Path (javax.ws.rs.Path)53 Produces (javax.ws.rs.Produces)52 IOException (java.io.IOException)51 GET (javax.ws.rs.GET)50 File (java.io.File)45 InputStream (java.io.InputStream)45 Test (org.junit.Test)44 WebApplicationException (javax.ws.rs.WebApplicationException)34 ByteArrayOutputStream (java.io.ByteArrayOutputStream)32 List (java.util.List)26 MediaType (javax.ws.rs.core.MediaType)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 ArrayList (java.util.ArrayList)20 Consumes (javax.ws.rs.Consumes)20 HashMap (java.util.HashMap)19 POST (javax.ws.rs.POST)19 FileOutputStream (java.io.FileOutputStream)17