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:android.security.cts.BrowserTest.java

private String getTargetFilePath() throws Exception {
    FileOutputStream out = mContext.openFileOutput("target.txt", mContext.MODE_WORLD_READABLE);
    Writer writer = new OutputStreamWriter(out, "UTF-8");
    writer.write("testing");
    writer.flush();
    writer.close();//from  w w  w . j  av  a  2 s . co m
    return mContext.getFileStreamPath("target.txt").getAbsolutePath();
}

From source file:org.joy.generator.engine.FreeMarkerImpl.java

@Override
public void processToFile(Map<String, Object> model, TemplateElement templateElement)
        throws TemplateEngineException {
    try {/*from ww w . ja va2s.co m*/
        Template template = config.getTemplate(templateElement.getTemplateFile(),
                templateElement.getEncoding());

        // 
        String targetPath = StringUtil
                .packagePathToFilePath(processToString(model, templateElement.getTargetPath()));

        // 
        String targetFileName = processToString(model, templateElement.getTargetFileName());

        File file = new File(targetPath + File.separator + targetFileName);
        File directory = new File(targetPath);
        if (!directory.exists()) {
            directory.mkdirs();
        }
        Writer out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(file), templateElement.getEncoding()));
        template.process(model, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        throw new TemplateEngineException(e.getMessage(), e);
    }
}

From source file:org.trimou.spring.web.view.TrimouView.java

@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    response.setContentType(getContentType());
    exposeRequestAttributesAsModel(model, request);
    final Writer writer = response.getWriter();
    try {//from  w w  w. j  a  va2  s .c om
        engine.getMustache(viewName).render(writer, model);
    } catch (NullPointerException e) {
        throw new MustacheException(getUrl() + " is not exist.", e);
    } finally {
        writer.flush();
    }
}

From source file:com.greenpepper.repository.FileSystemRepositoryTest.java

private String createDocument(File root, String fileName) throws IOException {
    File file = new File(root, fileName);
    IOUtil.createDirectoryTree(file.getParentFile());
    if (fileName.toLowerCase().endsWith(".html")) {
        Writer writer = null;
        try {/*from   w  w  w .j  ava  2s.c o  m*/
            writer = new FileWriter(file);
            writer.write(specification());
            writer.flush();
        } catch (IOException e) {
            IOUtil.closeQuietly(writer);
        }
    }
    return fileName;
}

From source file:org.opennms.ng.services.polloutagesconfig.PollOutagesConfigFactory.java

/**
 * {@inheritDoc}/*from   ww  w .java2 s . c om*/
 */
protected void saveXML(final String xmlString) throws IOException, MarshalException, ValidationException {
    getWriteLock().lock();

    try {
        File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.POLL_OUTAGES_CONFIG_FILE_NAME);

        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(cfgFile), "UTF-8");
        fileWriter.write(xmlString);
        fileWriter.flush();
        fileWriter.close();
    } finally {
        getWriteLock().unlock();
    }
}

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

/** {@inheritDoc} */
protected synchronized void saveXml(String xml) throws IOException {
    if (xml != null) {
        long timestamp = System.currentTimeMillis();
        File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.SNMP_INTERFACE_POLLER_CONFIG_FILE_NAME);
        logStatic().debug("saveXml: saving config file at " + timestamp + ": " + cfgFile.getPath());
        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(cfgFile), "UTF-8");
        fileWriter.write(xml);/* w w  w  . j  a va2  s  . c  o  m*/
        fileWriter.flush();
        fileWriter.close();
        logStatic().debug("saveXml: finished saving config file: " + cfgFile.getPath());
    }
}

From source file:com.pcms.temp.generate.MarkeWrite.java

public void processTemplate(String templateName, String templateEncoding, Map<?, ?> root, Writer out) {
    try {/*from  w  ww. j a va2 s  .  c o  m*/
        if (StringUtils.isEmpty(templateEncoding)) {
            templateEncoding = _defaultEncoding;
        }
        Template template = _config.getTemplate(templateName, templateEncoding);
        template.process(root, out);

        out.flush();
        out.close();
    } catch (IOException e) {
        _log.error(e.getMessage());
    } catch (TemplateException ex) {
        _log.error(ex.getMessage());
    }
}

From source file:cn.vlabs.umt.ui.actions.EditTemplateAction.java

public ActionForward saveTemplate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//from  ww w .j a  va  2 s .c o m

    EditTemplateForm etForm = (EditTemplateForm) form;

    StringBuffer sb = new StringBuffer();
    sb.append(EmailTemplate.SIGN_TITLE).append(etForm.getTitle());
    sb.append(EmailTemplate.SIGN_CONTENT).append(etForm.getContent());

    String templateFileDir = request.getSession().getServletContext().getRealPath("/");
    boolean succ = true;
    try {
        String path = getConfig().getStringProp(EmailTemplate.TEMPLATE_DIR, "WEB-INF/message/");
        String localeddir = path + "/" + Locale.getDefault().toString();
        File f = new File(templateFileDir + localeddir);
        if (!f.exists()) {
            localeddir = path + "/zh_CN";
        }
        templateFileDir += localeddir + "/" + etForm.getTarget();

        Writer writer = new OutputStreamWriter(new FileOutputStream(templateFileDir), "UTF-8");
        writer.write(sb.toString());
        writer.flush();
        writer.close();

    } catch (Exception e) {
        succ = false;
        log.error(e.getLocalizedMessage());
    }

    EmailTemplate email = getEmailTemplate(request, etForm.getTarget());
    request.setAttribute("template", email);
    if (succ) {
        request.setAttribute("succ", "emailtempt.update.success");
    } else {
        request.setAttribute("succ", "emailtempt.update.error");
    }
    request.setAttribute("act", request.getParameter("reAct"));
    return mapping.getInputForward();
}

From source file:com.gc.iotools.stream.writer.TeeWriter.java

/** {@inheritDoc} */
@Override/*from w w w  .j  a va 2s.c  o m*/
public void flush() throws IOException {
    if (!this.closeCalled) {
        for (int i = 0; i < this.destinations.length; i++) {
            final Writer stream = this.destinations[i];
            final long start = System.currentTimeMillis();
            stream.flush();
            this.writeTime[i] += System.currentTimeMillis() - start;
        }
    }
}

From source file:net.officefloor.plugin.web.http.template.section.HttpTemplateSectionIntegrationTest.java

/**
 * Writes the message./* w  w w. jav a 2  s. c  o m*/
 * 
 * @param connection
 *            {@link ServerHttpConnection}.
 * @param message
 *            Message.
 * @throws IOException
 *             If fails to write the message.
 */
private static void writeMessage(ServerHttpConnection connection, String message) throws IOException {
    Writer writer = connection.getHttpResponse().getEntityWriter();
    writer.write(message);
    writer.flush();
}