Examples of RobustFileWriter


Examples of net.sourceforge.processdash.util.RobustFileWriter

                    oldName = settingsFile;
                    destName = settingsFileRename;
                }

                File destFile = new File(destName);
                Writer out = new RobustFileWriter(destFile);
                fsettings.store(out);
                out.close();

                if (oldName != null) {
                    new File(oldName).delete();
                    settingsFile = destName;
                    settingsFileRename = null;
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

            name = name.substring(prefixLength).replace('=', EQUALS_SIGN_REPL);
            valuesToSave.add(name + (editable ? "=" : "==") + valStr);
        }

        // Write the saved values
        RobustFileWriter rfw;
        BufferedWriter out;
        try {
            String encoding = getDatasetEncoding();
           
            rfw = new RobustFileWriter(datafile.file, encoding);
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Encountered exception while opening "
                    + datafile.file.getPath() + "; save aborted", e);
            return;
        }

        try {
            out = new BufferedWriter(rfw);

            // if the data file has an include statement, write it to the file
            if (datafile.inheritsFrom != null) {
                out.write(includeTag + datafile.inheritsFrom);
                out.newLine();
            }

            // If the data file has a prefix, write it as a comment to the file
            if (datafile.prefix != null && datafile.prefix.length() > 0) {
                out.write("= Data for " + datafile.prefix);
                out.newLine();
            }

            for (Iterator i = valuesToSave.iterator(); i.hasNext();) {
                out.write((String) i.next());
                out.newLine();
            }

        } catch (IOException e) {
            logger.log(Level.SEVERE, "Encountered exception while writing to "
                    + datafile.file.getPath() + "; save aborted", e);
            try { rfw.abort(); } catch (Exception ex) {}
            return;
        }

        try {
            // Close output file
            out.flush();
            out.close();

            saveSuccessful = true;
            System.err.println("Saved " + datafile.file.getPath());
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Encountered exception while closing "
                    + datafile.file.getPath() + "; save aborted", e);
            try { rfw.abort(); } catch (Exception ex) {}
        }

      } finally {
          // if we couldn't successfully save the datafile, mark it as dirty.
          if (!saveSuccessful)              
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

    public CompletionStatus getCompletionStatus() {
        return completionStatus;
    }

    public void tryCancel() {
        RobustFileWriter ow = outWriter;
        if (ow != null) {
            try {
                ow.abort();
            } catch (Exception e) {}
        }
    }
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

        }
    }

    public void run() {
        try {
            outWriter = new RobustFileWriter(dest, "UTF-8");
            PrintWriter out = new PrintWriter(new BufferedWriter(outWriter));

            // Find and print any applicable task lists.
            Iterator i = ctx.getData().getKeys();
            Set taskListNames = new HashSet();
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

        maybeCleanup();
    }

    private File ensureTimeLogFileExists(File file) throws IOException {
        if (!file.exists()) {
            RobustFileWriter rout = new RobustFileWriter(file,
                    TIME_LOG_ENCODING);
            BufferedWriter out = new BufferedWriter(rout);
            TimeLogWriter.write(out, Collections.EMPTY_LIST.iterator());
        }
        return file;
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

        // 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();
        }
    }
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

  private boolean saveAsTabDelimited(Defect [] defects) {
    boolean savedSuccessfully = true;
    try {
      File defectFile = new File(defectLogFilename);
      Writer out = new BufferedWriter(new RobustFileWriter(defectFile));

      // write the defect info
      String newLine = System.getProperty("line.separator");
      if (defects != null)
        for (int i = 0;   i < defects.length;   i++)
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

    public synchronized boolean save() {
        if (saveFile == null || Settings.isReadOnly())
            return false;

        try {
            RobustFileWriter out = new RobustFileWriter(saveFile, "UTF-8");
            Iterator entries = new IteratorConcatenator(
                    new RenamingOperationsIterator(), //
                    modifications.values().iterator());
            TimeLogWriter.write(out, entries);
            saveFileTimestamp = saveFile.lastModified();
View Full Code Here

Examples of net.sourceforge.processdash.util.RobustFileWriter

  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) + " -->");
View Full Code Here

Examples of pspdash.RobustFileWriter

        // Create temporary files
        BufferedWriter out;

        try {
            out = new BufferedWriter(new RobustFileWriter(datafile.file));
        } catch (IOException e) {
            System.err.println("IOException " + e + " while opening " +
                               datafile.file.getPath() + "; save aborted");
            return;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.