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.ibm.watson.app.qaclassifier.tools.GenerateTrainingAndPopulationData.java

private static void writeGSON(String src, File output) throws IOException {
    FileWriter writer = null;
    try {//from   w w  w.  j  a v a  2s  . c  o  m
        writer = new FileWriter(output);
        writer.write(src);
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.galenframework.ide.devices.commands.DeviceCheckLayoutCommand.java

private static File createOnePixelFakeImage() {
    try {//ww  w  .java 2 s .  co m
        File file = File.createTempFile("1-pixel-image", ".png");
        FileWriter fw = new FileWriter(file);
        IOUtils.copy(DeviceCheckLayoutCommand.class.getResourceAsStream("/public/images/1-pixel-image.png"),
                fw);
        fw.flush();
        fw.close();
        return file;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:gov.nih.nci.caintegrator.application.query.GenomicDataFileWriter.java

/**
 * Writes a GenomicDataQueryResult to the given file.
 * @param result genomic query result to write in csv format.
 * @param csvFile to write file to./*from  ww  w.j  av  a2 s. co  m*/
 * @return csv file.
 */
public static File writeAsCsv(GenomicDataQueryResult result, File csvFile) {
    try {
        FileWriter writer = new FileWriter(csvFile);
        if (ResultsOrientationEnum.SUBJECTS_AS_COLUMNS.equals(result.getQuery().getOrientation())) {
            writeStandardOrientation(result, writer);
        } else {
            writeSubjectsAsRowsOrientation(result, writer);
        }
        writer.flush();
        writer.close();
    } catch (IOException e) {
        throw new IllegalArgumentException("Couldn't write file at the path " + csvFile.getAbsolutePath(), e);
    }
    return csvFile;
}

From source file:com.abid_mujtaba.fetchheaders.models.Account.java

private static void createEmptyAccountsJsonFile(File file) {
    try {/*from w w w.  java 2 s . com*/
        // We start by creating the JSON tree for an empty accounts.json file.
        JSONObject root = new JSONObject();
        JSONArray accounts = new JSONArray();

        root.put("accounts", accounts);

        // Save JSON to accounts.json
        FileWriter fw = new FileWriter(file); // Write root JSON object to file info.json
        fw.write(root.toString());
        fw.flush();
        fw.close();
    } catch (JSONException e) {
        Log.e(Resources.LOGTAG, "Exception raised while manipulate JSON objects.", e);
    } catch (IOException e) {
        Log.e(Resources.LOGTAG, "Exception raised while saving content to json file.", e);
    }
}

From source file:loadTest.loadTestLib.LUtil.java

public static void setUpResultFile() throws IOException {
    FileWriter writer = new FileWriter("loadTestResults.csv");
    writer.write("NodeCount,FileCount,FileSize,ResultTime\n");
    writer.flush();
    writer.close();// w w w. j  a  v  a2s .c o  m
}

From source file:net.amigocraft.mpt.util.MiscUtil.java

/**
 * Writes the repository store to disk. This method is <strong>not</strong> thread-safe; the stores much be locked
 * by the caller.// w w  w.j a  v a2s .  c  o  m
 * @throws IOException if an exception occurs while writing data to the disk
 */
public static void writeRepositoryStore() throws IOException {
    File file = new File(Main.plugin.getDataFolder(), "repositories.json");
    FileWriter writer = new FileWriter(file); // get a writer for the store file
    writer.write(JSONPrettyPrinter.toJSONString(Main.repoStore)); // write to disk
    writer.flush();
}

From source file:net.amigocraft.mpt.util.MiscUtil.java

/**
 * Writes the package store to disk. This method is <strong>not</strong> thread-safe; the stores much be locked
 * by the caller./*from www . j  a  va2  s.  co  m*/
 * @throws IOException if an exception occurs while writing data to the disk
 */
public static void writePackageStore() throws IOException {
    File file = new File(Main.plugin.getDataFolder(), "packages.json");
    FileWriter writer = new FileWriter(file); // get a writer for the store file
    writer.write(JSONPrettyPrinter.toJSONString(Main.packageStore)); // write to disk
    writer.flush();
}

From source file:it.geosolutions.geoserver.jms.impl.handlers.DocumentFile.java

/**
 * //from www .  j a  v a 2s .  c om
 * @param file
 * @param xml
 * @throws JDOMException
 * @throws IOException
 */
protected static void writer(File file, String xml) throws JDOMException, IOException {

    FileWriter writer = null;
    StringReader reader = null;
    try {
        writer = new FileWriter(file);
        reader = new StringReader(xml);

        char[] cbuf = new char[2048];
        int size = 0;
        while (reader.ready() && (size = reader.read(cbuf)) != -1) {
            writer.write(cbuf, 0, size);
        }

    } finally {
        writer.flush();
        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(reader);
    }
}

From source file:Main.java

public static void writeCSV(String phoneNo, String Message) {
    File root = Environment.getExternalStorageDirectory();
    File csvFile = new File(root, "/adspammer/log.csv");
    FileWriter writer = null;
    try {//from  ww  w.  j  av a  2  s  . com
        writer = new FileWriter(csvFile, true);

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd @ HH:mm:ss");
        Date date = new Date();
        System.out.println(dateFormat.format(date));

        writer.append(dateFormat.format(date).toString());
        writer.append(',');
        writer.append(phoneNo);
        writer.append(',');
        writer.append(Message);
        writer.append('\n');

        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.abid_mujtaba.fetchheaders.models.Account.java

private static void writeAccountsToJson() // Reads all Account objects (some of them updated) and uses them to write this data to accounts.json
{
    try {/*from w  w  w .  j av a 2s.  c o  m*/
        JSONObject jRoot = new JSONObject();
        JSONArray jAccounts = new JSONArray();

        for (int ii = 0; ii < sNumOfInstances; ii++) {
            JSONObject jAccount = new JSONObject();
            Account account = sInstances.get(ii);

            jAccount.put("name", account.name());
            jAccount.put("host", account.host());
            jAccount.put("username", account.username());
            jAccount.put("password", account.password());

            jAccounts.put(jAccount);
        }

        jRoot.put("accounts", jAccounts);

        // Save JSON to accounts.json
        FileWriter fw = new FileWriter(new File(Resources.INTERNAL_FOLDER, Settings.ACCOUNTS_JSON_FILE)); // Write root JSON object to file info.json
        fw.write(jRoot.toString());
        fw.flush();
        fw.close();
    } catch (JSONException e) {
        Log.e(Resources.LOGTAG, "Exception raised while manipulate JSON objects.", e);
    } catch (IOException e) {
        Log.e(Resources.LOGTAG, "Exception raised while saving content to json file.", e);
    }
}