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:info.novatec.testit.livingdoc.report.FileReportGenerator.java

@Override
public void closeReport(Report report) throws IOException {
    Writer out = null;
    try {/*from   www.jav  a 2  s.co  m*/
        File reportFile = new File(reportsDirectory, outputNameOf(report));
        reportFile.getParentFile().mkdirs();
        out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(reportFile.getAbsolutePath()), "UTF-8"));
        report.printTo(out);
        out.flush();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:info.novatec.testit.livingdoc.repository.FileSystemRepositoryTest.java

private String createDocument(File rootFile, String fileName) {

    File file = new File(rootFile, fileName);
    Writer writer = null;
    file.getParentFile().mkdirs();/*from  w w  w.ja v a 2  s. c  om*/
    try {
        if (fileName.toLowerCase().endsWith(".html")) {

            writer = new FileWriter(file);
            writer.write(specificationhtml());
            writer.flush();
        }
    } catch (IOException e) {
        IOUtils.closeQuietly(writer);
    }
    return fileName;
}

From source file:com.kurento.kmf.test.base.GridBrowserMediaApiTest.java

private void createRemoteScript(Node node, String remotePort, String remoteScript, String remoteFolder,
        String remoteChromeDriver, String remoteSeleniumJar, Browser browser, int maxInstances)
        throws IOException {

    // Create script for Node
    Configuration cfg = new Configuration();

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("remotePort", String.valueOf(remotePort));
    data.put("maxInstances", String.valueOf(maxInstances));
    data.put("hubIp", hubAddress);
    data.put("hubPort", String.valueOf(hubPort));
    data.put("remoteFolder", remoteFolder);
    data.put("remoteChromeDriver", remoteChromeDriver);
    data.put("remoteSeleniumJar", remoteSeleniumJar);
    data.put("pidFile", node.REMOTE_PID_FILE);
    data.put("browser", browser);

    cfg.setClassForTemplateLoading(GridBrowserMediaApiTest.class, "/templates/");

    try {/*from w w  w .j  av  a 2  s.com*/
        Template template = cfg.getTemplate(LAUNCH_SH + ".ftl");
        Writer writer = new FileWriter(new File(LAUNCH_SH));
        template.process(data, writer);
        writer.flush();
        writer.close();

    } catch (Exception e) {
        throw new RuntimeException("Exception while creating file from template", e);
    }

    // Copy script to remote node
    node.getRemoteHost().scp(LAUNCH_SH, remoteScript);
    node.getRemoteHost().execAndWaitCommand("chmod", "+x", remoteScript);
    Shell.run("rm", LAUNCH_SH);
}

From source file:com.tinspx.util.json.JSONParserTest.java

static void writeFormatted(String file, Object value) throws IOException {
    Writer caw = new BufferedWriter(new FileWriter(file), 1024 * 16);
    //        caw.write("start json\n");
    IndentingWriter.indentingBuilder().build().writeTo(caw, value);
    //        caw.write("\nend of json\n");
    caw.flush();
    caw.close();//from  w ww  . j a va 2s. co m
}

From source file:com.joliciel.talismane.extensions.standoff.ConllFileSplitter.java

/**
 * @param args/* w w w  .ja  va 2  s  .c o m*/
 * @throws IOException 
 * @throws UnsupportedEncodingException 
 */
public void split(String filePath, int startIndex, int sentencesPerFile, String encoding) {
    try {
        String fileBase = filePath;
        if (filePath.indexOf('.') > 0)
            fileBase = filePath.substring(0, filePath.lastIndexOf('.'));
        File file = new File(filePath);
        Scanner scanner = new Scanner(
                new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding)));

        boolean hasSentence = false;
        int currentFileIndex = startIndex;

        int sentenceCount = 0;
        Writer writer = null;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.length() == 0 && !hasSentence) {
                continue;
            } else if (line.length() == 0) {
                writer.write("\n");
                writer.flush();
                hasSentence = false;
            } else {
                if (!hasSentence) {
                    hasSentence = true;
                    sentenceCount++;
                }
                if (writer == null || sentenceCount % sentencesPerFile == 0) {
                    if (writer != null) {
                        writer.flush();
                        writer.close();
                    }
                    File outFile = new File(fileBase + "_" + df.format(currentFileIndex) + ".tal");
                    outFile.delete();
                    outFile.createNewFile();
                    writer = new BufferedWriter(
                            new OutputStreamWriter(new FileOutputStream(outFile, false), encoding));
                    currentFileIndex++;
                    hasSentence = false;
                }

                writer.write(line + "\n");
                writer.flush();
            }
        }
        if (writer != null) {
            writer.flush();
            writer.close();
        }
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:edu.vt.middleware.ldap.ldif.Ldif.java

/**
 * This will write the supplied LDAP search results to the supplied writer in
 * LDIF form./*from w  w w.  ja  v a2 s. c o  m*/
 *
 * @param  result  <code>LdapResult</code>
 * @param  writer  <code>Writer</code> to write to
 *
 * @throws  IOException  if an error occurs while writing to the output stream
 */
public void outputLdif(final LdapResult result, final Writer writer) throws IOException {
    writer.write(createLdif(result));
    writer.flush();
}

From source file:com.ewcms.publication.freemarker.generator.GeneratorBase.java

/**
 * ??//www  . j  a v  a2s. co  m
 * 
 * @param template   ?
 * @param parameters ?
 * @param rule       ??
 * @param writer     
 * @throws TemplateException
 * @throws IOException
 */
protected void write(Template template, Map<String, Object> parameters, UriRuleable rule, Writer writer)
        throws PublishException {

    setUriRuleParameters(rule, parameters);
    addUriRuleToProcessParameters(rule, parameters);

    try {
        template.process(parameters, writer);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        logger.error("Writer tempfile error {}", e.getMessage());
        throw new PublishException(e);
    } catch (TemplateException e) {
        logger.error("Freemarker proccess error {}", e.getMessage());
        throw new PublishException(e);
    }
}

From source file:de.minestar.contao2.manager.PlayerManager.java

@SuppressWarnings("unchecked")
/**/*from ww  w  .  j  a  v  a2 s . co  m*/
 * Store all online player in a JSON file, so we can display it on the website
 */
private void saveJSON() {
    JSONObject json = new JSONObject();
    // FILL JSON FILE WITH DATA

    json.put("ConnectedUsers", Bukkit.getOnlinePlayers().length);
    json.put("ConnectedDefaultUsers",
            this.groupMap.get(ContaoGroup.DEFAULT).size() + this.groupMap.get(ContaoGroup.X).size());
    json.put("ConnectedProbeUsers", this.groupMap.get(ContaoGroup.PROBE).size());
    json.put("ConnectedFreeUsers", this.groupMap.get(ContaoGroup.FREE).size());
    json.put("ConnectedPayUsers", this.groupMap.get(ContaoGroup.PAY).size());
    json.put("ConnectedAdmins", this.groupMap.get(ContaoGroup.ADMIN).size());
    json.put("FreeUserSlots", Settings.getFreeSlots());
    json.put("MaxPublicSlots", Settings.getMaxSlots());
    json.put("TotalSlots", Bukkit.getMaxPlayers());

    // WRITE JSON FILE
    try {
        File f = new File(Settings.getJSONFilePath());
        if (!f.exists())
            f.createNewFile();
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF8"));
        writer.write(json.toJSONString());
        writer.flush();
        writer.close();
    } catch (Exception e) {
        ConsoleUtils.printException(e, Core.NAME, "Can't save the JSON file!");
    }
}

From source file:edu.vt.middleware.ldap.ldif.Ldif.java

/**
 * This will write the supplied LDAP search results to the supplied writer in
 * LDIF form./* www.j a va2s  .  co  m*/
 *
 * @param  results  <code>Iterator</code> of LDAP search results
 * @param  writer  <code>Writer</code> to write to
 *
 * @throws  IOException  if an error occurs while writing to the output stream
 */
public void outputLdif(final Iterator<SearchResult> results, final Writer writer) throws IOException {
    writer.write(createLdif(results));
    writer.flush();
}

From source file:com.eqbridges.vertx.VerticleModuleMojo.java

private void createModJson(File verticleFolder) throws MojoExecutionException {
    String json = modJson();/*from  w  ww.j  a  v a 2  s. c o m*/
    File modJson = new File(verticleFolder, MOD_JSON);
    Writer w = null;
    try {
        w = new BufferedWriter(new FileWriter(modJson));
        w.write(json);
        w.flush();
        getLog().info(format("Configuration written to: [%s]", modJson.getAbsolutePath()));
    } catch (IOException e) {
        throw new MojoExecutionException(
                "unable to create module descriptor (" + modJson + "): " + e.getMessage());
    } finally {
        closeQuietly(w);
    }
}