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:UnpackedJarFile.java

public static void flush(Writer thing) {
    if (thing != null) {
        try {/* ww  w. j av  a  2 s.co  m*/
            thing.flush();
        } catch (Exception ignored) {
        }
    }
}

From source file:com.seyren.core.service.notification.IrcCatNotificationService.java

private void sendMessage(String ircCatHost, int ircCatPort, String message, String channel) throws IOException {
    Socket socket = new Socket(ircCatHost, ircCatPort);
    Closer closer = Closer.create();// w w w . j a v a  2  s .  com
    try {
        Writer out = closer.register(new OutputStreamWriter(socket.getOutputStream()));
        out.write(format("%s %s\n", channel, message));
        out.flush();
    } catch (IOException e) {
        socket.close();
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}

From source file:com.qcadoo.view.internal.JsonMapperHttpMessageConverter.java

@Override
protected void writeInternal(final Object value, final HttpOutputMessage outputMessage) throws IOException {
    Writer writer = null;
    try {//from  w  w w. java2 s .c  o m
        writer = new OutputStreamWriter(outputMessage.getBody(), CHARSET);
        writer.append(mapper.writeValueAsString(value));
        writer.flush();
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:br.com.pontocontrol.controleponto.controller.impl.ArquivoController.java

@Override
public boolean salvarArquivo(Writer writer) {
    try {//from  w  w  w .  j a  va2 s .  c om
        writer.flush();
        writer.close();
        return true;
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, "Erro ao fechar escritor de arquivos", ex);
        return false;
    }
}

From source file:com.teradata.tempto.internal.convention.sql.SqlQueryConventionBasedTest.java

private String resolveTemplates(String query) {
    try {/*w w  w . ja v  a  2  s . c o m*/
        Template template = new Template("name", new StringReader(query),
                new freemarker.template.Configuration());
        Map<String, Object> data = newHashMap();
        data.put("mutableTables", mutableTablesState().getNameInDatabaseMap());

        Writer writer = new StringWriter();
        template.process(data, writer);
        writer.flush();

        return writer.toString();
    } catch (TemplateException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.intel.cosbench.exporter.ScriptsLogExporter.java

@Override
public void export(Writer writer) throws IOException {
    exportWorkloadLog(writer);/*from ww w.ja v a2  s. c o m*/
    for (StageInfo stage : workload.getStageInfos())
        exportStageLog(writer, stage);
    writer.flush();
}

From source file:com.mitchellbosecke.pebble.spring.PebbleView.java

@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    response.setCharacterEncoding(this.characterEncoding);

    long startNanos = System.nanoTime();

    PebbleTemplate template = this.engine.getTemplate(this.templateName);

    // Add beans context
    model.put(BEANS_VARIABLE_NAME, new Beans(this.getApplicationContext()));

    // Add request & response
    model.put(REQUEST_VARIABLE_NAME, request);
    model.put(RESPONSE_VARIABLE_NAME, response);

    // Add session
    model.put(SESSION_VARIABLE_NAME, request.getSession(false));

    // Locale/*from   w ww  .jav a  2 s. c om*/
    Locale locale = RequestContextUtils.getLocale(request);

    final Writer writer = response.getWriter();
    try {
        template.evaluate(writer, model, locale);
    } finally {
        writer.flush();
    }

    if (TIMER_LOGGER.isDebugEnabled()) {
        long endNanos = System.nanoTime();

        BigDecimal elapsed = BigDecimal.valueOf(endNanos - startNanos);
        BigDecimal elapsedMs = elapsed.divide(BigDecimal.valueOf(NANOS_IN_SECOND), RoundingMode.HALF_UP);
        TIMER_LOGGER.debug("Pebble template \"{}\" with locale {} processed in {} nanoseconds (approx. {}ms)",
                new Object[] { this.templateName, locale, elapsed, elapsedMs });
    }
}

From source file:com.github.peterjanes.node.NpmPackageJsonMojo.java

/**
 *
 * @throws MojoExecutionException if anything unexpected happens.
 *///from ww  w  .j  av a 2 s.c om
public void execute() throws MojoExecutionException {
    if (!outputDirectory.exists()) {
        outputDirectory.mkdirs();
    }

    File packageJsonFile = new File(outputDirectory, "package.json");

    try {
        packageJsonFile.getParentFile().mkdirs();
        JSONObject packageJson = new JSONObject();
        packageJson.put("name", mavenProject.getName());
        packageJson.put("version", mavenProject.getProperties().getProperty("node.project.version"));
        packageJson.put("description", mavenProject.getDescription());
        packageJson.put("main", mainModule);

        List<Artifact> dependencyArtifacts = getNodeArtifacts(ResolutionScope.COMPILE);
        JSONObject dependencies = new JSONObject();
        // TODO: dependency.getVersion() may (and often will) return a
        // -SNAPSHOT. Figure out how to open the .tgz and pull in its
        // actual version, or rewrite the version as a range.
        for (Artifact dependency : dependencyArtifacts) {
            dependencies.put(dependency.getArtifactId(), dependency.getVersion());
        }
        addNpmDependencies(dependencies, npmDependencies);
        packageJson.put("dependencies", dependencies);

        List<Artifact> devDependencyArtifacts = getNodeArtifacts(ResolutionScope.TEST);
        JSONObject devDependencies = new JSONObject();
        for (Artifact devDependency : devDependencyArtifacts) {
            devDependencies.put(devDependency.getArtifactId(), devDependency.getVersion());
        }
        addNpmDependencies(devDependencies, npmTestDependencies);
        packageJson.put("devDependencies", devDependencies);

        JSONObject scripts = new JSONObject();
        scripts.put("test", "mocha -u exports -R xunit-file --recursive");
        scripts.put("coverage", "mocha -u exports -R mocha-lcov-reporter-file --recursive");
        packageJson.put("scripts", scripts);

        Writer w = new FileWriter(packageJsonFile);
        w.write(packageJson.toString());
        w.flush();
        w.close();
    } catch (IOException e) {
        throw new MojoExecutionException("Could not write package.json to " + packageJsonFile.getAbsolutePath(),
                e);
    }
}

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

/** {@inheritDoc} */
protected void saveXml(String xml) throws IOException {
    if (xml != null) {
        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(m_chartConfigFile), "UTF-8");
        fileWriter.write(xml);//from w w w  .  j a v  a  2s.  co m
        fileWriter.flush();
        fileWriter.close();
    }
}

From source file:com.openkm.util.impexp.RepositoryChecker.java

/**
 * Read document contents.//from  w  w  w  . j  a va 2  s .c o m
 */
private static ImpExpStats readDocument(String token, String docPath, boolean versions, Writer out,
        InfoDecorator deco) throws PathNotFoundException, RepositoryException, DatabaseException, IOException {
    log.debug("readDocument({})", docPath);
    DocumentModule dm = ModuleManager.getDocumentModule();
    File fsPath = new File(Config.NULL_DEVICE);
    ImpExpStats stats = new ImpExpStats();
    Document doc = dm.getProperties(token, docPath);

    try {
        FileOutputStream fos = new FileOutputStream(fsPath);
        InputStream is = dm.getContent(token, docPath, false);
        IOUtils.copy(is, fos);
        is.close();

        if (versions) { // Check version history
            for (Version ver : dm.getVersionHistory(token, docPath)) {
                is = dm.getContentByVersion(token, docPath, ver.getName());
                IOUtils.copy(is, fos);
                is.close();
            }
        }

        fos.close();
        out.write(deco.print(docPath, doc.getActualVersion().getSize(), null));
        out.flush();

        // Stats
        stats.setSize(stats.getSize() + doc.getActualVersion().getSize());
        stats.setDocuments(stats.getDocuments() + 1);
    } catch (RepositoryException e) {
        log.error(e.getMessage());
        stats.setOk(false);
        out.write(deco.print(docPath, doc.getActualVersion().getSize(), e.getMessage()));
        out.flush();
    }

    return stats;
}