Example usage for java.io FileWriter flush

List of usage examples for java.io FileWriter flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:com.niles.excel2json.objects.ExcelFile.java

public void writeToJson(JSONArray myJSONArray) {
    String jsFilePath = folderPath + sheetName.replaceAll(" ", "") + ".js";
    String jsonFilePath = folderPath + sheetName.replaceAll(" ", "") + ".json";

    logger.info("Writing file {}", jsFilePath);

    try {/*from  w w  w  .  ja  va2  s.  com*/
        // Create file
        FileWriter JSONFileStream = SystemTools.getFileWriter(jsFilePath);
        JSONFileStream.write("var " + sheetName.replaceAll("-", "").replaceAll(" ", "") + " = "
                + myJSONArray.toJSONString() + ";");
        // JSONFileStream.write(myJSONArray.toJSONString());
        JSONFileStream.flush();
        JSONFileStream.close();
    } catch (IOException ex) {
        logger.error("[{}]  Error writing JSON\r\n{}", jsFilePath, ex.getMessage());
    }

    logger.info("Writing file {}", jsonFilePath);

    try {
        // Create file
        FileWriter JSONFileStream = SystemTools.getFileWriter(jsonFilePath);
        JSONFileStream.write(myJSONArray.toJSONString());
        // JSONFileStream.write(myJSONArray.toJSONString());
        JSONFileStream.flush();
        JSONFileStream.close();
    } catch (IOException ex) {
        logger.error("[{}]  Error writing JSON\r\n{}", jsonFilePath, ex.getMessage());
    }
}

From source file:wsattacker.plugin.dos.dosExtension.result.ResultGenerator.java

private void saveResponseTimeOfUntamperedRequests(File untamperedRequests) throws IOException {
    // Save responseTime of untampered requestProbes!
    FileWriter writer = new FileWriter(untamperedRequests);

    saveResponseTime(writer, attackModel.getLogListUntamperedRequests());

    writer.flush();
    writer.close();/*from  w w  w  .java  2 s  . c o m*/
}

From source file:io.fabric8.vertx.maven.plugin.mojos.SetupMojo.java

private void save(File pomFile, Model model) throws MojoExecutionException {
    MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
    FileWriter pomFileWriter = null;
    try {/*from   w w w  .j  a v  a  2 s. c  om*/
        pomFileWriter = new FileWriter(pomFile);
        xpp3Writer.write(pomFileWriter, model);

        pomFileWriter.flush();
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write the pom.xml file", e);
    } finally {
        IOUtils.closeQuietly(pomFileWriter);
    }
}

From source file:com.mesosphere.dcos.cassandra.common.config.HeapConfig.java

public void writeHeapSettings(final Path path) throws IOException {
    FileWriter writer = null;
    try {//from w  w w  .ja  v  a  2  s.  c  o  m
        writer = new FileWriter(path.toFile(), false);
        List<String> settings = getHeapSettings();
        for (String setting : settings) {
            writer.write(setting + '\n');
        }
        writer.flush();
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException ex) {
            }
        }
    }
}

From source file:de.dekarlab.moneybuilder.model.parser.JsonBookSaver.java

/**
 * Save book to file.//w  w  w  .  j a va 2  s. c  o m
 * 
 * @param file
 * @param book
 * @throws Exception
 */
public static void saveBook(BookFile bookFile) throws Exception {
    FileWriter writer = null;
    JSONWriter jsonWriter = null;
    try {
        Book book = bookFile.getBook();
        writer = new FileWriter(bookFile.getFilePath());
        jsonWriter = new JSONWriter(writer);
        jsonWriter.object().key("book");
        jsonWriter.object();
        jsonWriter.key("name").value(book.getName());
        jsonWriter.key("currPeriodId").value(book.getCurrPeriodId());
        savePeriodBudget(book.getPeriodBudget(), jsonWriter);
        savePeriodValue(book.getPeriodValue(), jsonWriter);
        jsonWriter.key("assets");
        saveAccount(book.getAssetList(), jsonWriter);
        jsonWriter.key("liability");
        saveAccount(book.getLiabilityList(), jsonWriter);
        jsonWriter.key("income");
        saveAccount(book.getIncomeList(), jsonWriter);
        jsonWriter.key("expenses");
        saveAccount(book.getExpenseList(), jsonWriter);
        jsonWriter.key("periodList");
        savePeriodList(book.getPeriodList(), jsonWriter);
        jsonWriter.endObject();
        jsonWriter.endObject();
    } finally {
        if (writer != null) {
            writer.flush();
            writer.close();
        }
    }
}

From source file:com.l2jfree.gameserver.instancemanager.leaderboards.ArenaManager.java

public void saveData() {
    String pattern = "";

    for (Integer object : _ranks.keySet()) {
        ArenaRank ar = _ranks.get(object);

        pattern += object + " : " + ar.kills + "-" + ar.death + " : " + ar.name + "\n";
    }/*from  ww w  . j  a v a2  s .c o m*/

    File file = new File(Config.DATAPACK_ROOT, "data/arena.dat");
    try {
        FileWriter fw = new FileWriter(file);

        fw.write("# ownerId : kills-death-name\n");
        fw.write("# ===============================\n\n");
        fw.write(pattern);

        fw.flush();
        fw.close();
    } catch (IOException e) {
        _log.warn("", e);
    }
}

From source file:com.l2jfree.gameserver.instancemanager.leaderboards.FishermanManager.java

public void saveData() {
    String pattern = "";

    for (Integer object : _ranks.keySet()) {
        FishRank ar = _ranks.get(object);

        pattern += object + " : " + ar.cought + "-" + ar.escaped + " : " + ar.name + "\n";
    }//from  w  ww .j  av a  2s.c  o m

    File file = new File(Config.DATAPACK_ROOT, "data/fish.dat");
    try {
        FileWriter fw = new FileWriter(file);

        fw.write("# ownerId : cought-escaped-name\n");
        fw.write("# ===============================\n\n");
        fw.write(pattern);

        fw.flush();
        fw.close();
    } catch (IOException e) {
        _log.warn("", e);
    }
}

From source file:net.sf.reportengine.out.TestHtmlReportOutput.java

/**
 * Test method for//  w  ww. j ava2  s.  co  m
 * {@link net.sf.reportengine.out.AbstractFreemarkerReportOutput#close()}.
 */
@Test
public void testNonClosedWriter() throws IOException {
    final String OUTPUT_PATH = "./target/TestClosingWriter.html";
    FileWriter fileWriter = new FileWriter(OUTPUT_PATH);
    HtmlReportOutput classUnderTest = new HtmlReportOutput(fileWriter, false);
    classUnderTest.open();
    classUnderTest.output("emptyLine.ftl");
    classUnderTest.close();

    // at this point the writer should be already closed
    fileWriter.write("\nthis text has been added after HtmlReportOutput has been closed");
    fileWriter.flush();
    fileWriter.close();

    List<String> lines = IOUtils.readLines(new FileReader(OUTPUT_PATH));
    assertEquals(3, lines.size());
    assertEquals("<br/>", lines.get(0));
    assertEquals("<br/>", lines.get(1));
    assertEquals("this text has been added after HtmlReportOutput has been closed", lines.get(2));
}

From source file:edu.asu.bscs.csiebler.waypointdatabase.MainActivity.java

/**
 * @param v/*from  w  ww . j  ava  2  s.  c o  m*/
 */
public void exportWaypoints(View v) {
    File sdCard = Environment.getExternalStorageDirectory();

    FileWriter fw = null;

    try {
        fw = new FileWriter(sdCard.getAbsolutePath() + "/waypoints.json");
        fw.write(getJsonResults().toString());
    } catch (IOException e) {
        Log.w(getClass().getSimpleName(), e.getMessage());
    } finally {
        try {
            if (fw != null) {
                fw.flush();
                fw.close();
            }
        } catch (IOException e) {
            Log.w(getClass().getSimpleName(), e.getMessage());
        }
    }
}

From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheDatabaseTester.java

License:asdf

private File makeTemporaryEmptyFilelistFile() throws Exception {
    File res = new File(TestInfo.TEST_DIR, "filelist_empty.out");
    FileWriter fw = new FileWriter(res);

    StringBuilder fileContent = new StringBuilder("");

    fw.append(fileContent.toString());//from  w  ww  . j  ava 2 s . c o m
    fw.flush();
    fw.close();

    return res;
}