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.util.SystemUtils.java

/**
 * Generate the chgrp script for Unix systems.
 *
 * @return The full path to the chgrp script.
 *
 * @throws IOException If the generation fails.
 *//*  w  ww .j av a2s  .  c  o m*/
private static String generateChgrpScript() throws IOException {
    String scriptFile;
    FileWriter fout = null;
    try {
        scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "chgrpFolder.sh");
        fout = new FileWriter(scriptFile, false);
        StringBuilder b = new StringBuilder();
        b.append("#!/bin/sh\n");
        b.append("echo Changing ownership of $2 to $1\n");
        b.append("chgrp $1 $2 -R\n");
        LOGGER.debug("Writing script data to '{}'", scriptFile);
        fout.write(b.toString());
        fout.flush();
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ioe) {//ignore
            }
        }
    }
    return scriptFile;
}

From source file:edu.kit.dama.util.SystemUtils.java

/**
 * Generate the open script for Unix systems.
 *
 * @return The full path to the open script.
 *
 * @throws IOException If the generation fails.
 *//*  www.  j a v  a  2 s . c o m*/
private static String generateOpenScript() throws IOException {
    String scriptFile;
    FileWriter fout = null;
    try {
        scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "stickFolder.sh");
        fout = new FileWriter(scriptFile, false);
        StringBuilder b = new StringBuilder();
        b.append("#!/bin/sh\n");
        b.append("echo Changing access of $1 to 2770\n");
        b.append("chmod 2770 $1 -R\n");
        LOGGER.debug("Writing script data to '{}'", scriptFile);
        fout.write(b.toString());
        fout.flush();
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ioe) {//ignore
            }
        }
    }
    return scriptFile;
}

From source file:edu.kit.dama.transfer.client.types.TransferTask.java

/**
 * Writes a list of TransferTask entities in XML format into pFile
 *
 * @param pTasks The list of tasks to persist
 * @param pFile The file where the data will be written to
 *
 * @throws IOException If the file could not be written
 *///  w  w  w  . j  a v  a2 s . c  o  m
public static void toXML(List<TransferTask> pTasks, File pFile) throws IOException {
    StringBuilder buffer = new StringBuilder();
    FileWriter writer = null;
    buffer.append("<transferTasks>\n");
    try {
        writer = new FileWriter(pFile);
        int cnt = 0;
        for (TransferTask task : pTasks) {
            buffer.append(task.toXml()).append("\n");
            cnt++;
            if (cnt % 100 == 0) {//flush buffer all 100 tasks
                writer.write(buffer.toString());
                writer.flush();
                buffer = new StringBuilder();
            }
        }
        writer.write(buffer.toString());
        writer.write("</transferTasks>\n");
        writer.flush();
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException ioe) {
            }
        }
    }
}

From source file:com.bluexml.side.m2.repositoryBuilder.Builder.java

private static void writeShellScript(File script, List<File> poms) throws Exception {
    // create file
    if (!script.exists()) {
        script.createNewFile();//ww w  . j  a v a  2 s .c om
    }

    FileWriter fw = new FileWriter(script);

    // write header
    String header = "#!/bin/bash\n";
    header += "if [ $# -eq 1 ]; then" + "\n";
    header += "  MAVENREPO=$1" + "\n";
    header += "else" + "\n";
    header += "  echo \"Usage: patcher.sh MAVENREPO\"" + "\n";
    header += "  echo \"       with MAVENREPO = maven.repo.local absolute path\"" + "\n";
    header += "  exit -2" + "\n";
    header += "fi" + "\n";
    fw.write(header);

    for (File file : poms) {
        fw.write("mvn dependency:go-offline -P public -f " + file.getAbsolutePath()
                + " -Dmaven.repo.local=$MAVENREPO\n");
    }

    // save close
    fw.flush();
    fw.close();
}

From source file:com.sldeditor.test.unit.tool.vector.VectorToolTest.java

/**
 * Stream 2 file.//from  ww  w .  ja  v a  2  s .  co m
 *
 * @param in the in
 * @return the file
 * @throws IOException Signals that an I/O exception has occurred.
 */
private static File stream2file(InputStream in) throws IOException {
    final File tempFile = File.createTempFile(PREFIX, SUFFIX);
    try (FileOutputStream out = new FileOutputStream(tempFile)) {
        IOUtils.copy(in, out);
    }

    // Update the font for the operating system
    String newFont = getFontForOS();
    if (newFont.compareToIgnoreCase(DEFAULT_FONT) != 0) {
        BufferedReader br = new BufferedReader(new FileReader(tempFile));
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line.replace(DEFAULT_FONT, newFont));
                sb.append("\n");
                line = br.readLine();
            }
            try {
                FileWriter fileWriter = new FileWriter(tempFile);
                fileWriter.write(sb.toString());
                fileWriter.flush();
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        } finally {
            br.close();
        }
    }
    return tempFile;
}

From source file:foss.filemanager.core.Utils.java

public static void transform(File input, File output, Charset dstCharset) throws IOException {
    BufferedReader br = null;/*from   ww  w .ja  va 2  s.  c om*/
    FileWriter fileWriter = new FileWriter(output);
    try {
        String sCurrentLine;
        br = new BufferedReader(new FileReader(input));
        int i = 0;
        while ((sCurrentLine = br.readLine()) != null) {
            //Charset srcCharset = Charset.forName("UTF-8");
            InputStream is = new FileInputStream(input);
            Charset srcCharset = Charset.forName(guessEncoding(is));
            byte[] isoB = encode(sCurrentLine.getBytes(), srcCharset, dstCharset);
            fileWriter.write(new String(isoB, dstCharset));
            fileWriter.write("\n");
            System.out.println(i++);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            fileWriter.flush();
            fileWriter.close();
            if (br != null)
                br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:au.org.ala.spatial.analysis.layers.LayerDistanceIndex.java

public static void put(Map<String, Double> newDistances) {
    FileWriter fw = null;
    try {//w w w  .  j  ava  2s . c  om
        //create distances file if it does not exist.
        File layerDistancesFile = new File(IntersectConfig.getAlaspatialOutputPath() + LAYER_DISTANCE_FILE);
        if (!layerDistancesFile.exists()) {
            fw = new FileWriter(layerDistancesFile);
            fw.close();
        }

        fw = new FileWriter(layerDistancesFile, true);
        for (String key : newDistances.keySet()) {
            fw.write(key + "=" + newDistances.get(key) + "\n");
        }
        fw.flush();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

}

From source file:io.github.casnix.mcdropshop.util.configsys.Shops.java

public static boolean checkShopsFile() {
    File shopsFile = new File("./plugins/mcDropShop/Shops.json");

    if (!shopsFile.exists())
        return false;

    try {//w  w w .ja  va 2  s .co  m
        String configTable = new String(Files.readAllBytes(Paths.get("./plugins/mcDropShop/Shops.json")));

        JSONParser parser = new JSONParser();

        Object obj = parser.parse(configTable);

        JSONObject jsonObj = (JSONObject) obj;

        String listVersion = (String) jsonObj.get("listVersion");

        if (listVersion == null || !listVersion.equals("0.2.0")) {
            // Old version
            jsonObj.put("listVersion", "0.2.0");

            // Update Shops.json
            FileWriter shopsJSON = new FileWriter("./plugins/mcDropShop/Shops.json");

            shopsJSON.write(jsonObj.toJSONString());

            shopsJSON.flush();
            shopsJSON.close();
        }

        return true;
    } catch (Exception e) {
        Bukkit.getLogger().severe("mcDropShop failed on setup check in Shops.json");

        e.printStackTrace();

        return false;
    }
}

From source file:edu.kit.dama.util.SystemUtils.java

/**
 * Generate the lock script for Unix systems.
 *
 * @return The full path to the lock script.
 *
 * @throws IOException If the generation fails.
 *//* w w w .  j  a  va2  s .co m*/
private static String generateLockScript() throws IOException {
    String scriptFile;
    FileWriter fout = null;
    try {
        scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "lockFolder.sh");
        fout = new FileWriter(scriptFile, false);
        StringBuilder b = new StringBuilder();
        b.append("#!/bin/sh\n");
        b.append("echo Changing owner of $1 to `whoami`\n");
        b.append("chown `whoami` $1 -R\n");
        b.append("echo Changing access of $1 to 700\n");
        b.append("chmod 700 $1 -R\n");
        LOGGER.debug("Writing script data to '{}'", scriptFile);
        fout.write(b.toString());
        fout.flush();
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ioe) {//ignore
            }
        }
    }
    return scriptFile;
}

From source file:com.act.lcms.db.analysis.WaveformAnalysis.java

public static void printIntensityTimeGraphInCSVFormat(List<XZ> values, String fileName) throws Exception {
    FileWriter chartWriter = new FileWriter(fileName);
    chartWriter.append("Intensity, Time");
    chartWriter.append(NEW_LINE_SEPARATOR);
    for (XZ point : values) {
        chartWriter.append(point.getIntensity().toString());
        chartWriter.append(COMMA_DELIMITER);
        chartWriter.append(point.getTime().toString());
        chartWriter.append(NEW_LINE_SEPARATOR);
    }//from   www  . j a  v  a  2s. com
    chartWriter.flush();
    chartWriter.close();
}