Search in sources :

Example 11 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class WorkingTimeLog method doCleanup.

private synchronized void doCleanup(Iterator timeLogEntries) throws IOException {
    if (Settings.isReadOnly())
        return;
    // start by writing the output to a temporary file. Although we could
    // actually write directly to the destination file, that would be
    // relying on implementation details (of both TimeLogReader and
    // RobustFileWriter) that we should know nothing about.
    File tempFile = TempFileFactory.get().createTempFile("timelog", ".xml");
    RobustFileWriter rout = new RobustFileWriter(tempFile, TIME_LOG_ENCODING);
    BufferedWriter out = new BufferedWriter(rout);
    TimeLogWriter.write(out, timeLogEntries);
    out.close();
    long checksum1 = rout.getChecksum();
    // Now, copy the file we just created to its real destination.
    File destFile = getFile(TIME_LOG_FILENAME);
    Reader in = new BufferedReader(new InputStreamReader(new FileInputStream(tempFile), TIME_LOG_ENCODING));
    rout = new RobustFileWriter(destFile, TIME_LOG_ENCODING);
    out = new BufferedWriter(rout);
    int c;
    while (true) {
        c = in.read();
        if (c == -1)
            break;
        out.write(c);
    }
    out.flush();
    // we're done with the temporary file.  Close and delete it.
    try {
        in.close();
        tempFile.delete();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    long checksum2 = rout.getChecksum();
    if (checksum1 != checksum2) {
        // if the contents we just copied didn't match the first version of
        // the file we wrote, abort. This would only happen in the rare
        // circumstance when we wrote and verified one thing to the temp
        // file, then read it back differently.
        rout.abort();
        throw new IOException("Unable to save time log to file " + destFile);
    } else {
        rout.close();
        realTimeMods.clear();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter)

Example 12 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class MigrationToolTeam method convertDatafileContents.

private void convertDatafileContents(File dataFile) throws IOException {
    StringBuffer contents = slurpFile(dataFile);
    String oldIncludeStr = "#include <" + currentPID + "/";
    String newIncludeStr = "#include <" + targetPID + "/";
    StringUtils.findAndReplace(contents, oldIncludeStr, newIncludeStr);
    Writer out = new BufferedWriter(new RobustFileWriter(dataFile));
    out.write(contents.toString());
    out.close();
}
Also used : RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) BufferedWriter(java.io.BufferedWriter) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 13 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class MigrationToolTeam method updateSettingsXmlFile.

private void updateSettingsXmlFile() throws IOException {
    String jarName = tryToCopyProcessJar();
    File settingsFile = new File(teamDataDirectory, "settings.xml");
    StringBuffer settings = slurpFile(settingsFile);
    String oldPIDLine = "processID='" + currentPID + "'";
    String newPIDLine = "processID='" + targetPID + "'";
    StringUtils.findAndReplace(settings, oldPIDLine, newPIDLine);
    if (jarName != null) {
        Pattern p = Pattern.compile("/Templates/(.*\\.zip)");
        Matcher m = p.matcher(settings);
        if (m.find())
            settings.replace(m.start(1), m.end(1), XMLUtils.escapeAttribute(jarName));
    }
    Writer out = new BufferedWriter(new RobustFileWriter(settingsFile));
    out.write(settings.toString());
    out.close();
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 14 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class DashHierarchy method saveXML.

public void saveXML(String filename, String comment) throws IOException {
    if (Settings.isReadOnly())
        return;
    BufferedWriter out = new BufferedWriter(new RobustFileWriter(filename, "UTF-8"));
    out.write(XML_HEADER);
    out.newLine();
    out.newLine();
    if (comment != null && comment.length() != 0) {
        out.write("<!-- " + XMLUtils.escapeAttribute(comment) + " -->");
        out.newLine();
        out.newLine();
    }
    saveXMLNode(out, 0, PropertyKey.ROOT, false);
    out.close();
}
Also used : RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) BufferedWriter(java.io.BufferedWriter)

Example 15 with RobustFileWriter

use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.

the class TeamProject method saveColumns.

/** Save the project milestones */
private boolean saveColumns(File directory) {
    try {
        File f = new File(directory, COLUMNS_FILENAME);
        RobustFileWriter out = new RobustFileWriter(f, "UTF-8");
        BufferedWriter buf = new BufferedWriter(out);
        columnSpecs.getAsXML(buf);
        buf.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) File(java.io.File) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

RobustFileWriter (net.sourceforge.processdash.util.RobustFileWriter)22 BufferedWriter (java.io.BufferedWriter)17 File (java.io.File)11 IOException (java.io.IOException)11 Writer (java.io.Writer)6 InputStreamReader (java.io.InputStreamReader)2 Iterator (java.util.Iterator)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 MalformedURLException (java.net.MalformedURLException)1 PrivilegedAction (java.security.PrivilegedAction)1 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)1