Search in sources :

Example 11 with RobustFileOutputStream

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

the class ExportFileStream method copyToDestFile.

private void copyToDestFile(long checksum) throws IOException {
    RobustFileOutputStream out = new RobustFileOutputStream(directFile, false);
    FileUtils.copyFile(tempOutFile, out);
    long copySum = out.getChecksum();
    if (copySum == checksum) {
        out.close();
        target = directFile;
    } else {
        out.abort();
        throw new IOException("Error writing to " + directFile + " - checksums do not match");
    }
}
Also used : RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) IOException(java.io.IOException)

Example 12 with RobustFileOutputStream

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

the class TemplateSynchronizer method writeTemplateXml.

private void writeTemplateXml(List workflows, Map templates) throws IOException {
    XmlSerializer ser = XMLUtils.getXmlSerializer(true);
    genericOldSubtaskTemplate = (Element) templates.get(processID + "/IndivEmptyNode");
    genericNewSubtaskTemplate = (Element) templates.get(processID + "/Indiv2Task");
    phaseIDs = HierarchySynchronizer.initPhaseIDs(processID);
    effectivePhaseDataName = HierarchySynchronizer.getEffectivePhaseDataName(processID);
    projectNamePrefix = getProjectNamePrefix(projectPath);
    OutputStream out = new RobustFileOutputStream(destFile);
    ser.setOutput(out, ENCODING);
    ser.startDocument(ENCODING, null);
    ser.startTag(null, DOC_ROOT_ELEM);
    for (Iterator i = workflows.iterator(); i.hasNext(); ) {
        Element workflow = (Element) i.next();
        writeTemplate(ser, workflow);
    }
    ser.endTag(null, DOC_ROOT_ELEM);
    ser.flush();
    out.close();
}
Also used : OutputStream(java.io.OutputStream) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) Element(org.w3c.dom.Element) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) Iterator(java.util.Iterator) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 13 with RobustFileOutputStream

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

the class PermissionsManager method saveUsers.

/**
     * Save in-memory user information to disk.
     */
private void saveUsers() {
    try {
        if (Settings.isReadOnly() || Settings.isPersonalMode())
            return;
        // open a file to save the users
        File tmp = TempFileFactory.get().createTempFile("users", ".dat");
        OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(tmp));
        // start an XML document
        XmlSerializer xml = XMLUtils.getXmlSerializer(true);
        xml.setOutput(out, "UTF-8");
        xml.startDocument("UTF-8", null);
        xml.startTag(null, USERS_TAG);
        if (usersTimestamp != null)
            xml.attribute(null, TIMESTAMP_ATTR, XMLUtils.saveDate(usersTimestamp));
        // write XML for each user
        for (User u : getAllUsers()) {
            writeUser(xml, u);
        }
        // end the document and close the file
        xml.endTag(null, USERS_TAG);
        xml.ignorableWhitespace(System.lineSeparator());
        xml.endDocument();
        out.close();
        // add a tamper-deterrent thumbprint to the file
        TamperDeterrent.getInstance().addThumbprint(tmp, usersFile, TamperDeterrent.FileType.XML);
        tmp.delete();
        // from now forward, require a version of the dashboard that
        // understands and enforces users, roles and permissions
        DataVersionChecker.registerDataRequirement("pspdash", "2.3.2");
        // flush data so the PDES can update server-side permissions
        if (bridgedUrl != null)
            workingDir.flushData();
        this.usersDirty = false;
    } catch (IOException ioe) {
        logger.log(Level.WARNING, "Could not save users to " + usersFile, ioe);
    } catch (LockFailureException lfe) {
        logger.log(Level.WARNING, "Could not flush user data to server", lfe);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 14 with RobustFileOutputStream

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

the class DefectLog method saveAsXML.

private void saveAsXML(Defect[] defects) {
    try {
        RobustFileOutputStream out = new RobustFileOutputStream(defectLogFilename);
        if (defects != null && defects.length > 0) {
            XmlSerializer ser = XMLUtils.getXmlSerializer(true);
            ser.setOutput(out, XmlConstants.ENCODING);
            ser.startDocument(XmlConstants.ENCODING, null);
            ser.startTag(null, "defectLog");
            for (int i = 0; i < defects.length; i++) if (defects[i] != null)
                defects[i].toXml(ser);
            ser.endTag(null, "defectLog");
            ser.endDocument();
        }
        out.close();
    } catch (IOException e) {
        System.out.println("IOException: " + e);
    }
    ;
}
Also used : RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 15 with RobustFileOutputStream

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

the class PermissionsManager method saveRoles.

/**
     * Save in-memory role information to disk.
     */
private void saveRoles() {
    try {
        if (Settings.isReadOnly() || Settings.isPersonalMode())
            return;
        // open a file to save the roles
        File tmp = TempFileFactory.get().createTempFile("roles", ".dat");
        OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(tmp));
        // start an XML document
        XmlSerializer xml = XMLUtils.getXmlSerializer(true);
        xml.setOutput(out, "UTF-8");
        xml.startDocument("UTF-8", null);
        xml.startTag(null, ROLES_TAG);
        if (rolesTimestamp != null)
            xml.attribute(null, TIMESTAMP_ATTR, XMLUtils.saveDate(rolesTimestamp));
        // write XML for each role
        for (Role r : getAllRoles()) {
            writeRole(xml, r);
        }
        // end the document and close the file
        xml.endTag(null, ROLES_TAG);
        xml.ignorableWhitespace(System.lineSeparator());
        xml.endDocument();
        out.close();
        // add a tamper-deterrent thumbprint to the file
        TamperDeterrent.getInstance().addThumbprint(tmp, rolesFile, TamperDeterrent.FileType.XML);
        tmp.delete();
        // from now forward, require a version of the dashboard that
        // understands and enforces users, roles and permissions
        DataVersionChecker.registerDataRequirement("pspdash", "2.3.2");
        this.rolesDirty = false;
    } catch (IOException ioe) {
        logger.log(Level.WARNING, "Could not save roles to " + rolesFile, ioe);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Aggregations

RobustFileOutputStream (net.sourceforge.processdash.util.RobustFileOutputStream)17 File (java.io.File)10 IOException (java.io.IOException)9 BufferedOutputStream (java.io.BufferedOutputStream)8 OutputStream (java.io.OutputStream)7 XmlSerializer (org.xmlpull.v1.XmlSerializer)5 OutputStreamWriter (java.io.OutputStreamWriter)3 BufferedWriter (java.io.BufferedWriter)2 Iterator (java.util.Iterator)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1