Example usage for java.io OutputStream flush

List of usage examples for java.io OutputStream flush

Introduction

In this page you can find the example usage for java.io OutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:com.orange.clara.cloud.servicedbdumper.filer.compression.GzipCompressing.java

@Async
public Future<Boolean> gunziptIt(OutputStream outputStream, InputStream inputStream) throws IOException {
    logger.debug("Start uncompressing...");
    GZIPInputStream gzis = new GZIPInputStream(inputStream);
    ByteStreams.copy(gzis, outputStream);

    outputStream.flush();
    outputStream.close();/*  www . j  av  a2s  .com*/
    gzis.close();
    inputStream.close();
    logger.debug("Finish uncompressing");
    return new AsyncResult<Boolean>(true);
}

From source file:com.subgraph.vega.internal.model.requests.RequestLogEntity.java

@Override
public void writeTo(OutputStream outstream) throws IOException {
    if (outstream == null) {
        throw new IllegalArgumentException("Output stream may not be null");
    }//from   w  w  w. j  av a 2s  .c  o  m
    outstream.write(content);
    outstream.flush();
}

From source file:com.k42b3.kadabra.handler.Ftp.java

public void uploadFile(String path, byte[] content) throws Exception {
    logger.info(basePath + "/" + path);

    OutputStream os = client.storeFileStream(basePath + "/" + path);

    if (os != null) {
        os.write(content);//from ww w . ja  va  2 s .c o m

        os.flush();
        os.close();

        client.completePendingCommand();
    }
}

From source file:com.npower.dl.OMADownloadServlet.java

public void doDownload(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String uri = request.getRequestURI();
    log.info("Download Service: Download Content: uri: " + uri);

    String downloadID = DownloadFactory.parserDownloadID(uri);

    FumoDownloadUpdate download = new FumoDownloadUpdate();
    download.setDownloadID(downloadID);// w w w.j a v  a2 s .  c o  m
    try {
        byte[] content = download.getContent();
        if (content != null && content.length > 0) {
            log.info("Download Service: Request download ID: " + downloadID + ",Content size: "
                    + content.length);
            response.setContentType(download.getContentType());
            response.setContentLength(content.length);
            OutputStream out = response.getOutputStream();
            out.write(content);
            out.flush();
            //out.close();
        }
    } catch (Exception ex) {
        throw new ServletException(ex);
    } finally {
    }
}

From source file:com.xpn.xwiki.plugin.svg.SVGPlugin.java

public void outputSVGImage(String content, String extension, int height, int width, XWikiContext context)
        throws IOException, SVGConverterException {
    byte[] svgbytes = getSVGImage(content, extension, height, width);
    XWikiResponse response = context.getResponse();
    context.setFinished(true);/*from ww w  . ja  v a2  s .  co  m*/
    response.setContentLength(svgbytes.length);
    response.setContentType(context.getEngineContext().getMimeType("toto." + extension));
    OutputStream os = response.getOutputStream();
    os.write(svgbytes);
    os.flush();
}

From source file:com.sdl.odata.controller.AbstractODataController.java

/**
 * Transfers data from an {@code ODataResponse} into an {@code HttpServletResponse}.
 *
 * @param oDataResponse   The {@code ODataResponse}.
 * @param servletResponse The {@code HttpServletResponse}
 * @throws java.io.IOException If an I/O error occurs.
 *///from   ww  w .j a v a  2  s.c  om
private void fillServletResponse(ODataResponse oDataResponse, HttpServletResponse servletResponse)
        throws IOException {
    servletResponse.setStatus(oDataResponse.getStatus().getCode());

    for (Map.Entry<String, String> entry : oDataResponse.getHeaders().entrySet()) {
        servletResponse.setHeader(entry.getKey(), entry.getValue());
    }

    byte[] body = oDataResponse.getBody();
    if (body != null && body.length != 0) {
        OutputStream out = servletResponse.getOutputStream();
        out.write(oDataResponse.getBody());
        out.flush();
    }
}

From source file:com.thinkberg.moxo.dav.PutHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    try {/* ww  w. j av  a  2 s.co m*/
        LockManager.getInstance().checkCondition(object, getIf(request));
    } catch (LockException e) {
        if (e.getLocks() != null) {
            response.sendError(SC_LOCKED);
        } else {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
        return;
    }

    // it is forbidden to write data on a folder
    if (object.exists() && FileType.FOLDER.equals(object.getType())) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    FileObject parent = object.getParent();
    if (!parent.exists()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    if (!FileType.FOLDER.equals(parent.getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    InputStream is = request.getInputStream();
    OutputStream os = object.getContent().getOutputStream();
    log("PUT sends " + request.getHeader("Content-length") + " bytes");
    log("PUT copied " + Util.copyStream(is, os) + " bytes");
    os.flush();
    object.close();

    response.setStatus(HttpServletResponse.SC_CREATED);
}

From source file:biz.astute.test.simulator.rest.SimulatorRestHandler.java

/**
 * {@inheritDoc}/*from   ww w.ja v  a 2 s . co  m*/
 */
@Override
public final void handle(final String pTarget, final Request pBaseRequest, final HttpServletRequest pRequest,
        final HttpServletResponse pResponse) throws IOException, ServletException {

    // Lets set the default
    pResponse.setContentType("text/plain");

    try {

        DataResourceInterface dataResourceInterface = DataResourceFactory
                .getDataResource(new RequestContext(pRequest, pResponse));

        for (String header : dataResourceInterface
                .getProperties(DataResourceInterface.HEADER_RESPONSE_PREFIX)) {
            pResponse.setHeader(header.substring(DataResourceInterface.HEADER_RESPONSE_PREFIX.length() + 1),
                    dataResourceInterface.getPropertyValue(header));
        }

        String status = dataResourceInterface.getPropertyValue(DataResourceInterface.RESPONSE_STATUS);
        if (StringUtils.isEmpty(status)) {
            status = Integer.toString(HttpStatus.OK_200);
        }
        pResponse.setStatus(Integer.parseInt(status));
        String val = dataResourceInterface.getPropertyValue(DataResourceInterface.DATA_RESPONSE_VALUE);
        if (val == null) {

            try (InputStream inStream = dataResourceInterface
                    .getResourceData(DataResourceInterface.DATA_RESPONSE_RESOURCE);) {
                if (inStream != null) {
                    OutputStream outStream = pResponse.getOutputStream();
                    pResponse.setContentLength(IOUtils.copy(inStream, outStream));
                    outStream.flush();
                }
            }
        } else {
            pResponse.getWriter().print(val);
        }

    } catch (DataResourceException | NoSuchAlgorithmException execp) {
        LOGGER.log(Level.SEVERE, "Error Processing " + pRequest.getRequestURL(), execp);
        pResponse.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
        pResponse.getWriter()
                .print("Error Processing " + pRequest.getRequestURL() + " - " + execp.getMessage());
    }
    pResponse.flushBuffer();
    pBaseRequest.setHandled(true);
}

From source file:com.nesscomputing.httpclient.factory.httpclient4.BetterStringEntity.java

@Override
public void writeTo(final OutputStream outstream) throws IOException {
    if (outstream == null) {
        throw new IllegalArgumentException("Output stream may not be null");
    }/*from w ww  . j  a v a 2 s .  c  om*/
    outstream.write(this.content);
    outstream.flush();
}

From source file:at.tugraz.sss.serv.util.SSFileU.java

public static void readFileBytes(final OutputStream outStream, final FileInputStream fileIn,
        final Integer transmissionSize) throws SSErr {

    try {// w  w  w  .  j a  v  a2 s  . c  o  m
        final byte[] fileBytes = new byte[transmissionSize];
        int read;

        while ((read = fileIn.read(fileBytes)) != -1) {

            if (fileBytes.length == 0 || read <= 0) {

                outStream.write(new byte[0]);
                outStream.flush();
                break;
            }

            outStream.write(fileBytes, 0, read);
            outStream.flush();
        }
    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (outStream != null) {
            try {
                outStream.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }

        if (fileIn != null) {
            try {
                fileIn.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }
    }
}