Search in sources :

Example 1 with ExternalResourceManager

use of net.sourceforge.processdash.tool.export.mgr.ExternalResourceManager in project processdash by dtuma.

the class FileBackupManager method createExternalizedBackupFile.

private File createExternalizedBackupFile(URL backup) throws IOException {
    // open the existing backup file as a ZIP stream
    ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(backup.openStream()));
    // create a temporary file for externalizing purposes
    File result = TempFileFactory.get().createTempFile("pdash-backup", ".zip");
    result.deleteOnExit();
    ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(result)));
    zipOut.setLevel(9);
    ExternalResourceManager extMgr = ExternalResourceManager.getInstance();
    // copy all the files from the existing backup into the externalized
    // backup (but skip any files that appear to be externalized)
    ZipEntry e;
    while ((e = zipIn.getNextEntry()) != null) {
        String filename = e.getName();
        if (extMgr.isArchivedItem(filename))
            continue;
        ZipEntry eOut = new ZipEntry(filename);
        eOut.setTime(e.getTime());
        zipOut.putNextEntry(eOut);
        FileUtils.copyFile(zipIn, zipOut);
        zipOut.closeEntry();
    }
    zipIn.close();
    // now, ask the external resource manager to augment the ZIP.
    extMgr.addExternalResourcesToBackup(zipOut);
    zipOut.finish();
    zipOut.close();
    return result;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ExternalResourceManager(net.sourceforge.processdash.tool.export.mgr.ExternalResourceManager) BufferedInputStream(java.io.BufferedInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ExternalResourceManager (net.sourceforge.processdash.tool.export.mgr.ExternalResourceManager)1