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:edu.kit.dama.staging.util.DataOrganizationUtils.java

/**
 * Serialize the provided tree as XML into the provided file.
 *
 * @param pTree The tree to write.//from  www  .  j  a  v a  2s .  com
 * @param pDestination The file to write into.
 */
public static void writeTreeToFile(IFileTree pTree, File pDestination) {
    if (pTree == null) {
        throw new IllegalArgumentException("Argument 'pTree' must not be 'null'");
    }

    if (pDestination == null) {
        throw new IllegalArgumentException("Argument 'pDestination' must not be 'null'");
    }

    XStream x = new XStream();
    x.alias("fileTree", IFileTree.class);
    LOGGER.debug("Writing data organization tree to file {}", pDestination.getPath());
    FileWriter w = null;
    try {
        w = new FileWriter(pDestination);
        x.toXML(pTree, w);
        w.flush();
    } catch (IOException ioe) {
        LOGGER.error("Failed to write data organization tree", ioe);
    } finally {
        try {
            if (w != null) {
                w.close();
            }
        } catch (IOException ignored) {
        }
    }
}

From source file:presenter.MainPresenter.java

@Override
public void saveEmissionsequenceToFile(ActionEvent e) {
    JFileChooser fc = new JFileChooser();

    if (fc.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {//from  w  w  w. j  a va  2s.c o  m
            FileWriter fw = new FileWriter(file);
            fw.write(this.emissionsequenceModel.toString());
            fw.flush();
            fw.close();
            this.displayStatus("File was written successfully!");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

From source file:com.aionemu.gameserver.dataholders.DataLoader.java

/**
 * Saves data to the file. Used only by {@link SpawnData}.
 *
 * @return true if the data was successfully saved, false - if some error
 * occurred./*from w  ww.  j  a va 2  s. c o m*/
 */
public boolean saveData() {
    String desc = PATH + getSaveFile();

    log.info("Saving " + desc);

    FileWriter fr = null;
    try {
        fr = new FileWriter(desc);

        saveEntries(fr);

        fr.flush();

        return true;
    } catch (Exception e) {
        log.error("Error while saving " + desc, e);
        return false;
    } finally {
        if (fr != null) {
            try {
                fr.close();
            } catch (Exception e) {
                log.error("Error while closing save data file", e);
            }
        }
    }
}

From source file:com.xpn.xwiki.plugin.svg.SVGPlugin.java

public byte[] getSVGImage(int hashCode, String content, String extension, int height, int width)
        throws IOException, SVGConverterException {
    File dfile = getTempFile(hashCode, "svg");
    if (!dfile.exists()) {
        FileWriter fwriter = new FileWriter(dfile);
        fwriter.write(content);/* ww  w  .j a  v  a2 s. co m*/
        fwriter.flush();
        fwriter.close();
    }

    File ofile = getTempFile(hashCode, extension);
    // TODO implement conversion HERE

    SVGConverter conv = new SVGConverter();
    // TODO PNG ONLY
    conv.setDestinationType(DestinationType.PNG);
    conv.setDst(ofile);
    conv.setHeight(height);
    conv.setWidth(width);
    String[] sources = { dfile.getAbsolutePath() };
    conv.setSources(sources);
    conv.execute();

    FileInputStream fis = new FileInputStream(ofile);
    byte[] result = new byte[(int) ofile.length()];
    try {
        fis.read(result);
    } finally {
        IOUtils.closeQuietly(fis);
    }

    return result;
}

From source file:de.joinout.criztovyl.tools.json.JSONFile.java

/**
 * Writes the JSON data to the file./*w w  w  . ja v a 2s. co  m*/
 */
public void write() {

    try {
        //Create file if not exists
        path.touch();

        //Create writer
        final FileWriter fw = new FileWriter(path.getFile());

        //Write
        fw.write(data);

        //Flush 'n' close
        fw.flush();
        fw.close();
    } catch (final IOException e) {
        logger.catching(e);
    }

}

From source file:info.novatec.testit.livingdoc.server.rpc.runner.report.FileReportGenerator.java

@Override
public void closeReport(Report report) throws IOException {
    FileWriter out = null;
    try {//from   w  ww  .j  ava2  s  .  co  m
        File reportFile = new File(reportsDirectory, outputNameOf(report));
        reportFile.getParentFile().mkdirs();
        out = new FileWriter(reportFile);
        report.printTo(out);
        out.flush();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:bigtweet.model.StudyingBeacons.java

/**
 * Extra ouput file to generate a chart 
 * call plotBeaconStudy in R project to obtain chart
 *///from w  w  w .  ja v a  2 s .c o  m
private void generateBatchOuputForChart(JSONArray parametersValues, int parametersValuesIndex,
        double meanEndorsers) {

    JSONObject parameters = (JSONObject) parametersValues.get(parametersValuesIndex);//parameters
    JSONObject aux = new JSONObject();
    aux.put("links", parameters.get("beaconLinksNumber"));
    aux.put("centrality", parameters.get("beaconLinksCentrality"));
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    DecimalFormat df = new DecimalFormat("0.000", otherSymbols);
    aux.put("meanEndorsers", df.format(meanEndorsers));
    JSONForChart.add(aux);

    //write json file
    FileWriter file;
    try {
        file = new FileWriter(batchOutputFileForChart);
        file.write(JSONForChart.toJSONString());
        file.flush();
        file.close();
    } catch (Exception ex) {
        Logger.getLogger(BTSimBatch.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.github.aneveux.docukes.generators.MarkdownGenerator.java

/**
 * Creates a markdown file in the target repository containing some
 * documentation generated from the specified Java class
 * /* ww w  .java  2 s .  c o  m*/
 * @param clazz
 *            a Java class containing some cukes annotations
 * @param methods
 *            the methods of the Java class which are actually annotated
 *            with Cukes
 * @param withDate
 *            defines if the markdown file should contain the time on which
 *            generation has been performed
 */
public void write(JavaClassSource clazz, List<MethodSource<JavaClassSource>> methods, boolean withDate) {
    final File file = new File(target.getPath() + "/" + clazz.getName() + ".md");
    try {
        final FileWriter writer = new FileWriter(file);
        writer.write(generateContent(clazz, methods, withDate));
        writer.flush();
        writer.close();
    } catch (final IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:edu.missouri.bas.bluetooth.equivital.EquivitalRunnable.java

protected void writeToFile(File f, String toWrite) throws IOException {
    FileWriter fw = new FileWriter(f, true);
    fw.write(toWrite + '\n');
    fw.flush();
    fw.close();/*from   w  ww  .  ja  v  a 2  s  . c o m*/
}

From source file:JSON.WriteProductJSON.java

public int write() {
    products.put("products", details);
    try {/*w w  w  .j av  a2 s .  com*/

        // Writing to a file  
        File file = new File("Path to products.json");
        file.createNewFile();
        FileWriter fileWriter = new FileWriter(file);
        System.out.println("Writing JSON object to file");
        System.out.println("-----------------------");
        System.out.print(products);

        fileWriter.write(products.toJSONString());
        fileWriter.flush();
        fileWriter.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return 0;
}