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:org.dasein.cloud.util.requester.entities.DaseinEntity.java

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

    outstream.write(content);
    outstream.flush();
}

From source file:io.wcm.handler.media.impl.AbstractMediaFileServlet.java

/**
 * Send binary data to output stream. Respect optional content disposition header handling.
 * @param binaryData Binary data array.// w  ww.  j a  v  a 2  s.c  o  m
 * @param contentType Content type
 * @param request Request
 * @param response Response
 * @throws IOException
 */
protected void sendBinaryData(byte[] binaryData, String contentType, SlingHttpServletRequest request,
        SlingHttpServletResponse response) throws IOException {

    // set content type and length
    response.setContentType(contentType);
    response.setContentLength(binaryData.length);

    // Handling of the "force download" selector
    if (RequestPath.hasSelector(request, SELECTOR_DOWNLOAD)) {
        // Overwrite MIME type with one suited for downloads
        response.setContentType(ContentType.DOWNLOAD);

        // Construct disposition header
        StringBuilder dispositionHeader = new StringBuilder("attachment;");
        String suffix = request.getRequestPathInfo().getSuffix();
        suffix = StringUtils.stripStart(suffix, "/");
        if (StringUtils.isNotEmpty(suffix)) {
            dispositionHeader.append("filename=\"").append(suffix).append('\"');
        }

        response.setHeader(HEADER_CONTENT_DISPOSITION, dispositionHeader.toString());
    }

    // write binary data
    OutputStream out = response.getOutputStream();
    out.write(binaryData);
    out.flush();

}

From source file:net.portalblockz.portalbot.webinterface.WebIntHandler.java

private void sendReply(HttpExchange httpExchange, String response, String ctntType) {
    try {/*from w ww.  j ava 2s . c o  m*/
        //String response = "<html><head><title>portalBot</title></head><body>"+msg+"</body></html>";
        Map<String, String> newHeaders = new HashMap<>();
        newHeaders.put("Date", Utils.getDate());
        newHeaders.put("Server", "portalBot IRC Bot Webserver");
        newHeaders.put("Content-Length", response.length() + "");
        newHeaders.put("Content-Type", ctntType);
        for (Map.Entry<String, String> entry : newHeaders.entrySet()) {
            List<String> l = new ArrayList<>();
            l.add(entry.getValue());
            httpExchange.getResponseHeaders().put(entry.getKey(), l);
        }
        httpExchange.sendResponseHeaders(200, response.length());
        OutputStream os = httpExchange.getResponseBody();
        os.write(response.getBytes());
        os.flush();
        os.close();
        httpExchange.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:fr.paris.lutece.portal.service.editor.ParserBbcodeServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * /*www .j a  va 2 s  . com*/
 * @param request
 *            servlet request
 * @param response
 *            servlet response
 * @throws ServletException
 *             the servlet Exception
 * @throws IOException
 *             the io exception
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String strValue = request.getParameter(PARAMETER_DATA);
    String strEscaped = StringEscapeUtils.escapeHtml(strValue);
    String strValueReturn = (strValue != null) ? EditorBbcodeService.getInstance().parse(strEscaped) : "";
    OutputStream out = response.getOutputStream();
    out.write(strValueReturn.getBytes(AppPropertiesService.getProperty(PROPERTY_ENCODING)));
    out.flush();
    out.close();
}

From source file:ar.com.zauber.commons.web.transformation.processors.impl.DocumentBuilderFactoryDocumentProvider.java

/** @see DocumentProvider#serialize(Document, OutputStream) */
public final void serialize(final Document document, final OutputStream os) {
    try {/*from  w  w  w .  ja  va2  s. co m*/
        TransformerFactory.newInstance().newTransformer().transform(new DOMSource(document),
                new StreamResult(os));
        os.flush();
    } catch (IOException e) {
        throw new UnhandledException(e);
    } catch (TransformerException e) {
        throw new UnhandledException(e);
    }
}

From source file:eionet.rpcserver.servlets.XmlRpcRouter.java

/**
 * Standard doPost implementation.//from w  w w.j  a  v  a  2 s  .  c  om
 *
 */
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    /*
    System.out.println("=============================");
    System.out.println("============POST ============");
    System.out.println("=============================");
            
    */
    byte[] result = null;
    //authorization here!

    String encoding = null;
    try {
        Hashtable<Object, Object> props = UITServiceRoster.loadProperties();

        encoding = (String) props.get(UITServiceRoster.PROP_XMLRPC_ENCODING);
    } catch (Exception e) {
    }

    if (encoding != null) {
        req.setCharacterEncoding(encoding);
        XmlRpc.setEncoding(encoding);
    }

    //get authorization header from request
    String auth = req.getHeader("Authorization");
    if (auth != null) {

        if (!auth.toUpperCase().startsWith("BASIC")) {
            throw new ServletException("wrong kind of authorization!");
        }

        //get encoded username and password
        String userPassEncoded = auth.substring(6);

        String userPassDecoded = new String(Base64.decodeBase64(userPassEncoded));

        //split decoded username and password
        StringTokenizer userAndPass = new StringTokenizer(userPassDecoded, ":");
        String username = userAndPass.nextToken();
        String password = userAndPass.nextToken();

        result = xmlrpc.execute(req.getInputStream(), username, password);
    } else {
        //log("================ 2 ");
        result = xmlrpc.execute(req.getInputStream());
    }

    res.setContentType("text/xml");
    res.setContentLength(result.length);
    OutputStream output = res.getOutputStream();
    output.write(result);
    output.flush();

    //req.getSession().invalidate(); //???????????????
}

From source file:org.openmeetings.servlet.outputhandler.BackupExportFacade.java

@Override
protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
        throws ServletException, IOException {

    try {//  ww w .j a v  a  2 s. c o  m

        if (getBackupExport() == null) {
            OutputStream out = httpServletResponse.getOutputStream();

            String msg = "Server is not booted yet";

            out.write(msg.getBytes());

            out.flush();
            out.close();

            return;
        }

        getBackupExport().service(httpServletRequest, httpServletResponse, getServletContext());

    } catch (Exception er) {
        log.error("ERROR ", er);
        log.debug("Error exporting: " + er);
        er.printStackTrace();
    }
}

From source file:org.seedstack.seed.rest.internal.hal.HalMessageBodyWriter.java

@Override
public void writeTo(HalRepresentation halRepresentation, Class<?> type, Type genericType,
        Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
        OutputStream entityStream) throws IOException, WebApplicationException {
    ObjectMapper objectMapper = new ObjectMapper();
    try {//from  ww  w.  j  a v  a  2  s .c  o  m
        entityStream.write(objectMapper.writeValueAsBytes(halRepresentation));
        entityStream.flush();
    } catch (JsonProcessingException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.joyent.manta.http.entity.ExposedByteArrayEntity.java

@Override
public void writeTo(final OutputStream out) throws IOException {
    Validate.notNull(out, "OutputStream should not be null");

    out.write(this.buffer, this.offset, this.length);
    out.flush();
}

From source file:br.ufc.mdcc.mpos.net.endpoint.service.DiscoveryService.java

private void send(OutputStream os, String mposServiceResquest) throws IOException {
    os.write(mposServiceResquest.getBytes(), 0, mposServiceResquest.length());
    os.flush();
}