Example usage for java.io FileWriter append

List of usage examples for java.io FileWriter append

Introduction

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

Prototype

@Override
    public Writer append(CharSequence csq) throws IOException 

Source Link

Usage

From source file:SwiftWork.java

private static void appendToRemoteTmpList(String object, boolean close) {
    File logFile = new File(getBenchITTemp(), REMOTE_TEMP_LOG_FILE);
    try {/*w  w  w .j  a  va2s .  c o m*/
        FileWriter fileWriter = new FileWriter(logFile, true);
        fileWriter.append(object + '\n');
        if (close)
            fileWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:SwiftWork.java

private static void appendToLocalTmpList(String file, boolean close) {
    File logFile = new File(getBenchITTemp(), LOCAL_TEMP_LOG_FILE);
    try {/*  w w w. j  ava  2 s.  com*/
        FileWriter fileWriter = new FileWriter(logFile, true);
        fileWriter.append(file + '\n');
        if (close)
            fileWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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);
    }/* w  w w. j  a va 2  s  .  c o  m*/
    chartWriter.flush();
    chartWriter.close();
}

From source file:ubic.basecode.util.FileTools.java

/**
 * Create or update the modification date of the given file. If the file does not exist, create it.
 * //w  w  w .j a  v  a2  s . co  m
 * @param f
 * @throws IOException
 */
public static void touch(File f) throws IOException {
    if (!f.exists()) {
        FileWriter w = new FileWriter(f);
        w.append("");
        w.close();
    }
    f.setLastModified(new Date().getTime());
}

From source file:nl.utwente.trafficanalyzer.GeoTagger.java

public static void tagFilesInFolder(Path dir) {

    Path path = Paths.get("D:\\work\\NetBeans projects\\trafficanalyzer\\sampledata\\alles_untar\\sensors.csv");
    List list1 = readCsvFile(path.toFile());
    for (Object line : list1) {
        CSVRecord record = (CSVRecord) line;
        sensors.put(record.get(0),//  w w  w .  ja va2s. com
                new LatLong(Double.parseDouble(record.get(1)), Double.parseDouble(record.get(2))));
    }

    FileWriter writer = null;

    File folder = dir.toFile();
    File[] listOfFiles = folder.listFiles();
    Arrays.sort(listOfFiles);

    System.err.println("sorting files...");
    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile()) {
            List list2 = readCsvFile(listOfFiles[i]);
            try {
                writer = new FileWriter(listOfFiles[i]);

                for (Object line : list2) {
                    CSVRecord record = (CSVRecord) line;
                    for (int j = 0; j < 6; j++) {
                        writer.append(record.get(j));
                        writer.append(',');
                    }
                    //end line
                    writer.append('\n');
                }

                writer.flush();
                writer.close();
            } catch (IOException ex) {
                Logger.getLogger(GeoTagger.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

}

From source file:au.org.ala.layers.grid.GridClassBuilder.java

static void exportSLD(String filename, String name, ArrayList<Integer> maxValues, ArrayList<String> labels) {
    StringBuffer sld = new StringBuffer();
    /* header *///from  ww w .  j a  v  a  2  s.c  om
    sld.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    sld.append(
            "<sld:StyledLayerDescriptor xmlns=\"http://www.opengis.net/sld\" xmlns:sld=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:gml=\"http://www.opengis.net/gml\" version=\"1.0.0\">");
    sld.append("<sld:NamedLayer>");
    sld.append("<sld:Name>raster</sld:Name>");
    sld.append(" <sld:UserStyle>");
    sld.append("<sld:Name>raster</sld:Name>");
    sld.append("<sld:Title>A very simple color map</sld:Title>");
    sld.append("<sld:Abstract>A very basic color map</sld:Abstract>");
    sld.append("<sld:FeatureTypeStyle>");
    sld.append(" <sld:Name>name</sld:Name>");
    sld.append("<sld:FeatureTypeName>Feature</sld:FeatureTypeName>");
    sld.append(" <sld:Rule>");
    sld.append("   <sld:RasterSymbolizer>");
    sld.append(" <sld:Geometry>");
    sld.append(" <ogc:PropertyName>geom</ogc:PropertyName>");
    sld.append(" </sld:Geometry>");
    sld.append(" <sld:ChannelSelection>");
    sld.append(" <sld:GrayChannel>");
    sld.append("   <sld:SourceChannelName>1</sld:SourceChannelName>");
    sld.append(" </sld:GrayChannel>");
    sld.append(" </sld:ChannelSelection>");
    sld.append(" <sld:ColorMap type=\"intervals\">");

    //sort labels
    List<String> sortedLabels = new ArrayList<String>(labels);
    Collections.sort(sortedLabels);

    /* outputs */
    sld.append("\n<sld:ColorMapEntry color=\"#ffffff\" opacity=\"0\" quantity=\"1\"/>\n");
    for (int j = 0; j < sortedLabels.size(); j++) {
        int i = 0;
        while (i < labels.size()) {
            if (labels.get(i).equals(sortedLabels.get(j)))
                break;
            i++;
        }
        sld.append("<sld:ColorMapEntry color=\"#" + getHexColour(colours[i % colours.length]) + "\" quantity=\""
                + (maxValues.get(i) + 1) + ".0\" label=\"" + labels.get(i) + "\" opacity=\"1\"/>\r\n");
    }

    /* footer */
    sld.append(
            "</sld:ColorMap></sld:RasterSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer></sld:StyledLayerDescriptor>");

    /* write */
    FileWriter fw = null;
    try {
        fw = new FileWriter(filename);
        fw.append(sld.toString());
        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:cn.kk.exia.MangaDownloader.java

private final static void checkAndDump(final String line, final Logger log, final String targetDir) {
    if (line.contains("An Error Has Occurred")) {
        try {//ww  w . ja  v  a2  s  .  c  om
            Thread.sleep(
                    (60 * MangaDownloader.sleepBase) + (int) (Math.random() * 120 * MangaDownloader.sleepBase));
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (line.contains("your IP address")) {
        log.err("??" + line);
        try {
            Thread.sleep(
                    (60 * MangaDownloader.sleepBase) + (int) (Math.random() * 120 * MangaDownloader.sleepBase));
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (MangaDownloader.dump) {
        try {
            final File dumpFile = new File(targetDir + File.separator + "exia-dump.xml");
            if (!dumpFile.isFile()) {
                log.err("dump: " + dumpFile.getAbsolutePath());
            }
            final FileWriter writer = new FileWriter(dumpFile, true);

            writer.append(line);
            writer.append('\n');
            writer.close();
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:bizlogic.Records.java

public static void writeCSV(Connection DBcon, String record_id) throws SQLException {

    Statement st;//from w ww.  j  a v  a2s.co  m
    ResultSet rs = null;

    System.out.println("WriteCSV started");

    try {
        st = DBcon.createStatement();
        rs = st.executeQuery("SELECT * FROM PUBLIC.t" + record_id);
        System.out.println("Result set read finished");
    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(Records.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);
    }

    try {

        String DELIMITER = ",";
        String NEW_LINE = "\n";
        String FILE_HEADER = "Time,Series";

        System.out.println("Delete old file");
        FileWriter csvFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/Data/" + record_id + ".csv");

        //BufferedWriter csvFile = new BufferedWriter(
        //        new OutputStreamWriter(new FileOutputStream(new File(
        //                "/var/lib/tomcat8/webapps/ROOT/Records/Data/" + 
        //                        record_id + ".csv"))));

        csvFile.write("");

        csvFile.append(FILE_HEADER);
        csvFile.append(NEW_LINE);

        Calendar calendar = new GregorianCalendar();

        System.out.println("Writing file...");
        while (rs.next()) {

            long time_stamp = rs.getLong("time");
            double value = rs.getDouble("value");
            String _year;
            String _month;
            String _day;
            String _hour;
            String _min;
            String _sec;

            calendar.setTimeInMillis(time_stamp);

            _year = Integer.toString(calendar.get(Calendar.YEAR));
            _month = Integer.toString(calendar.get(Calendar.MONTH) + 1);
            _day = Integer.toString(calendar.get(Calendar.DAY_OF_MONTH));
            _hour = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
            _min = Integer.toString(calendar.get(Calendar.MINUTE));
            _sec = Integer.toString(calendar.get(Calendar.SECOND));

            csvFile.append(_year + "/" + _month + "/" + _day + " " + _hour + ":" + _min + ":" + _sec + DELIMITER
                    + Double.toString(value) + NEW_LINE); //new Date("2009/07/19 12:34:56")

        }
        System.out.print("File written");
        rs.close();
        //csvFile.flush();
        csvFile.close();
    }

    catch (IOException ex) {
        Logger.getLogger(Records.class.getName()).log(Level.WARNING, null, ex);
    }
}

From source file:org.apache.geode.management.internal.cli.CliUtil.java

public static void runLessCommandAsExternalViewer(Result commandResult, boolean isError) {
    StringBuilder sb = new StringBuilder();
    String NEW_LINE = System.getProperty("line.separator");

    while (commandResult.hasNextLine()) {
        sb.append(commandResult.nextLine()).append(NEW_LINE);
    }//from   w w  w.  j a v a 2 s.  c  o m

    File file = null;
    FileWriter fw;
    try {
        file = File.createTempFile("gfsh_output", "less");
        fw = new FileWriter(file);
        fw.append(sb.toString());
        fw.close();
        File workingDir = file.getParentFile();
        Process p = Runtime.getRuntime()
                .exec(new String[] { "sh", "-c",
                        "LESSOPEN=\"|color %s\" less -SR " + file.getName() + " < /dev/tty > /dev/tty " }, null,
                        workingDir);
        p.waitFor();
    } catch (IOException | InterruptedException e) {
        Gfsh.printlnErr(e.getMessage());
    } finally {
        if (file != null)
            file.delete();
    }
}

From source file:com.ibm.research.rdf.store.runtime.service.sql.StoreHelper.java

private static void doSql(Connection conn, Backend backend, String t) {
    String generateSqlOnly = System.getProperty("com.ibm.rdf.generateStoreSQL");
    if (generateSqlOnly != null) {
        try {/*  w  ww  .  j a  va 2s  .co  m*/
            FileWriter fw = new FileWriter(generateSqlOnly, true);
            fw.append(t);
            fw.append(backend == Store.Backend.postgresql || backend == Store.Backend.shark ? ";\n" : "\n");
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
            assert false;
        }
    } else {
        SQLExecutor.executeUpdate(conn, t);
    }
}