Example usage for java.io Writer flush

List of usage examples for java.io Writer flush

Introduction

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

Prototype

public abstract void flush() throws IOException;

Source Link

Document

Flushes the stream.

Usage

From source file:de.thischwa.pmcms.view.renderer.ExportRenderThread.java

@Override
public void run() {
    if (controller.isCanceled()) {
        this.interrupt();
        return;/*from ww  w . j  a va  2 s  . co m*/
    }

    File outputFile = PathTool.getExportFile(renderable, poExtension);
    Writer fileWriter = null;
    try {
        fileWriter = new BufferedWriter(new FileWriter(outputFile));
        velocityRenderer.render(fileWriter, renderable, ViewMode.EXPORT);
        fileWriter.flush();
    } catch (Exception e) {
        controller.interrupt(this, e);
    } finally {
        IOUtils.closeQuietly(fileWriter);
    }
    logger.debug("Rendered: ".concat(renderable.toString()));
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.usage.UsageLoggerFileImpl.java

private void log(String msg) throws UsageLoggerException {
    try {/*www .  j av a2s.c  o m*/
        Writer out = getWriter();
        out.append(msg);
        out.flush();
    } catch (IOException ioe) {
        throw new UsageLoggerException(ioe);
    }
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.SessionDump.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    Page page = new Page();

    HttpSession session = request.getSession(getURI(request).indexOf("new") > 0);

    page.title("Session Dump Servlet: ");

    TableForm tf = new TableForm(response.encodeURL(getURI(request)));
    tf.method("POST");

    if (session == null) {
        page.add("<H1>No Session</H1>");
        tf.addButton("Action", "New Session");
    } else {//from  w  ww  .  j av  a2 s .c  o  m
        try {
            tf.addText("ID", session.getId());
            tf.addText("State", session.isNew() ? "NEW" : "Valid");
            tf.addText("Creation", new Date(session.getCreationTime()).toString());
            tf.addText("Last Access", new Date(session.getLastAccessedTime()).toString());
            tf.addText("Max Inactive", "" + session.getMaxInactiveInterval());

            tf.addText("Context", "" + session.getServletContext());

            Enumeration keys = session.getAttributeNames();
            while (keys.hasMoreElements()) {
                String name = (String) keys.nextElement();
                String value = session.getAttribute(name).toString();
                tf.addText(name, value);
            }

            tf.addTextField("Name", "Property Name", 20, "name");
            tf.addTextField("Value", "Property Value", 20, "value");
            tf.addTextField("MaxAge", "MaxAge(s)", 5, "");
            tf.addButtonArea();
            tf.addButton("Action", "Set");
            tf.addButton("Action", "Remove");
            tf.addButton("Action", "Invalidate");

            page.add(tf);
            tf = null;
            if (request.isRequestedSessionIdFromCookie())
                page.add("<P>Turn off cookies in your browser to try url encoding<BR>");

            if (request.isRequestedSessionIdFromURL())
                page.add("<P>Turn on cookies in your browser to try cookie encoding<BR>");

        } catch (IllegalStateException e) {
            log.debug(LogSupport.EXCEPTION, e);
            page.add("<H1>INVALID Session</H1>");
            tf = new TableForm(getURI(request));
            tf.addButton("Action", "New Session");
        }
    }

    if (tf != null)
        page.add(tf);

    Writer writer = response.getWriter();
    page.write(writer);
    writer.flush();
}

From source file:com.panet.imeta.trans.step.errorhandling.AbstractFileErrorHandler.java

private void close(Writer outputStreamWriter) throws KettleException {
    if (outputStreamWriter != null) {
        try {/*from   www  . ja va2  s.co  m*/
            outputStreamWriter.flush();
        } catch (IOException exception) {
            log.logError(Messages.getString("AbstractFileErrorHandler.Log.CouldNotFlushContentToFile"), //$NON-NLS-1$
                    exception.getLocalizedMessage());
        }
        try {
            outputStreamWriter.close();
        } catch (IOException exception) {
            throw new KettleException(
                    Messages.getString("AbstractFileErrorHandler.Exception.CouldNotCloseFile"), exception); //$NON-NLS-1$
        } finally {
            outputStreamWriter = null;
        }
    }
}

From source file:org.apache.juneau.rest.client.RestRequestEntity.java

@Override /* BasicHttpEntity */
public void writeTo(OutputStream os) throws IOException {
    if (output instanceof InputStream) {
        IOPipe.create(output, os).closeOut().run();
    } else if (output instanceof Reader) {
        IOPipe.create(output, new OutputStreamWriter(os, IOUtils.UTF8)).closeOut().run();
    } else {//from   w w w. ja v  a2 s .co  m
        try {
            if (serializer == null) {
                // If no serializer specified, just close the stream.
                os.close();
            } else if (!serializer.isWriterSerializer()) {
                OutputStreamSerializer s2 = (OutputStreamSerializer) serializer;
                s2.serialize(output, os);
                os.flush();
                os.close();
            } else {
                Writer w = new OutputStreamWriter(os, IOUtils.UTF8);
                WriterSerializer s2 = (WriterSerializer) serializer;
                s2.serialize(output, w);
                w.flush();
                w.close();
            }
        } catch (SerializeException e) {
            throw new org.apache.juneau.rest.client.RestCallException(e);
        }
    }
}

From source file:com.norconex.collector.core.AbstractCollectorConfig.java

public void saveToXML(Writer out) throws IOException {
    try {//  ww w  .  jav a2 s. c  om
        out.flush();
        EnhancedXMLStreamWriter writer = new EnhancedXMLStreamWriter(out);
        writer.writeStartElement("collector");
        writer.writeAttributeClass("class", getClass());
        writer.writeAttribute("id", getId());

        writer.writeElementString("logsDir", getLogsDir());
        writer.writeElementString("progressDir", getProgressDir());
        writer.flush();

        out.write("<crawlers>");
        out.flush();
        if (crawlerConfigs != null) {
            for (ICrawlerConfig crawlerConfig : crawlerConfigs) {
                crawlerConfig.saveToXML(out);
                out.flush();
            }
        }
        out.write("</crawlers>");
        out.flush();

        saveCollectorConfigToXML(out);

        writer.writeEndElement();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }

}

From source file:com.veight.mail.template.MailTemplateLocal.java

public String makeContent(String templateName, Map<String, String> root) {
    Writer out = null;
    try {// w w  w  . ja v a  2  s.c  o m
        Template template = configuration.getTemplate(templateName);
        out = new StringWriter();
        template.process(root, out);

        out.flush();
        return out.toString();
    } catch (IOException | TemplateException ex) {
        logger.error("Fail to get content from freemaker. [mailTemplate={}][mail={}]", templateName, ex);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException ex) {
                logger.error("Fail to close StringWriter.", ex);
            }
        }
    }
    return StringUtils.EMPTY;
}

From source file:com.nominanuda.web.http.BaseHttpTest.java

protected void dumpFailures(Writer w) throws IOException {
    for (String f : failures) {
        w.write("failure:" + f + "\n");
    }/*from   ww w . j  av  a  2  s  .c o m*/
    w.flush();
}

From source file:com.openedit.error.HtmlErrorHandler.java

/**
 * @see org.jpublish.ErrorHandler#handleError(JPublishError)
 *///from   w  w w.j av  a 2 s .c  o m
public boolean handleError(Throwable error, WebPageRequest context) {
    OpenEditException exception = null;
    if (context != null) {
        try {
            if (!(error instanceof OpenEditException)) {
                exception = new OpenEditException(error); //we need the toStacktrace method
            } else {
                exception = (OpenEditException) error;
            }
            if (exception instanceof ContentNotAvailableException) {
                try {
                    context.getResponse().setStatus(404);
                    return true;
                } catch (Exception ex) {
                    //ignored
                    log.debug("Ignored:" + ex);
                }
            }

            if (!context.hasRedirected() && context.getResponse() != null) {
                try {
                    context.getResponse().setStatus(500);
                } catch (Exception ex) {
                    //ignored
                    log.debug("Ignored:" + ex);
                }
            }
            error.printStackTrace();
            String pathWithError = exception.getPathWithError();
            if (pathWithError == null) {
                pathWithError = context.getPage().getPath();
                exception.setPathWithError(pathWithError);

            }
            context.putPageValue("editPath", exception.getPathWithError());
            context.putPageValue("oe-exception", exception); //must be a top level thing since we create a new context
            PageStreamer pages = (PageStreamer) context.getPageValue(PageRequestKeys.PAGES);

            //exception.getPathWithError()
            //Page content = pages.getPage();
            Page content = context.getPage();
            String errorpagepath = content.getProperty("errorpage");

            Page errorPage = null;

            if (errorpagepath == null) {
                errorpagepath = "/system/errorpage.html";
            }
            errorPage = pages.getPage(errorpagepath);

            if (!errorPage.exists()) {
                log.error("No error page found" + errorPage.getPath());
                return false;
            } else {
                Writer out = context.getWriter();
                errorPage.generate(context, new Output(out, null));
                out.flush();
            }
        } catch (Exception ex) {
            //Do not throw an error here is it will be infinite
            log.error(ex);
            ex.printStackTrace();
            try {
                context.getWriter().write("Check error logs: " + ex);
                //throw new OpenEditRuntimeException(ex);
            } catch (Throwable ex1) {
                log.error(ex1);
            }
        }
        return true;
    }
    return false;
}

From source file:com.netxforge.oss2.config.NotificationFactory.java

/** {@inheritDoc} */
protected void saveXML(String xmlString) throws IOException {
    if (xmlString != null) {
        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(m_noticeConfFile), "UTF-8");
        fileWriter.write(xmlString);//from   w w  w .ja  va 2s  . c om
        fileWriter.flush();
        fileWriter.close();
    }
}