Search in sources :

Example 91 with ZipInputStream

use of java.util.zip.ZipInputStream in project processdash by dtuma.

the class CompressedInstanceLauncher method collectLaunchTargetPrefixes.

private static void collectLaunchTargetPrefixes(List result, String prepend, ZipInputStream in) throws IOException {
    ZipEntry e;
    while ((e = in.getNextEntry()) != null) {
        String filename = e.getName().replace('\\', '/');
        if (filename.endsWith(DATA_DIR_FILE_ITEM)) {
            int prefixLen = filename.length() - DATA_DIR_FILE_ITEM.length();
            String prefix = filename.substring(0, prefixLen);
            result.add(prepend + prefix);
            result.remove(WBS_DIR_FILE_ITEM);
        } else if (filename.equals(WBS_DIR_FILE_ITEM) && "".equals(prepend) && result.isEmpty()) {
            result.add(WBS_DIR_FILE_ITEM);
        } else if (isCompressedInstanceFilename(filename) && filename.toLowerCase().indexOf("backup/") == -1) {
            ZipInputStream subIn = openZipStream(in, filename);
            collectLaunchTargetPrefixes(result, prepend + filename + SUBZIP_SEPARATOR, subIn);
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry)

Example 92 with ZipInputStream

use of java.util.zip.ZipInputStream in project processdash by dtuma.

the class CompressedInstanceLauncher method uncompressData.

private void uncompressData(File tempDir, ZipInputStream in, String fullPrefix) throws IOException {
    String prefix = fullPrefix;
    String remainingPrefix = null;
    if (fullPrefix.indexOf(SUBZIP_SEPARATOR) != -1) {
        int pos = fullPrefix.indexOf(SUBZIP_SEPARATOR);
        prefix = fullPrefix.substring(0, pos);
        remainingPrefix = fullPrefix.substring(pos + SUBZIP_SEPARATOR.length());
    }
    ZipEntry e;
    while ((e = in.getNextEntry()) != null) {
        String filename = e.getName().replace('\\', '/');
        if (remainingPrefix != null) {
            if (filename.equals(prefix)) {
                ZipInputStream subZip = openZipStream(in, filename);
                uncompressData(tempDir, subZip, remainingPrefix);
            }
        } else if (filename.startsWith(prefix) && !e.isDirectory()) {
            filename = filename.substring(prefix.length());
            File destFile = new File(tempDir, filename);
            if (filename.indexOf('/') != -1)
                destFile.getParentFile().mkdirs();
            if ("wbs.xml".equals(destFile.getName()))
                sawWbsXml = true;
            else if ("projDump.xml".equals(destFile.getName()))
                sawProjDump = true;
            FileUtils.copyFile(in, destFile);
            if (e.getTime() != -1) {
                destFile.setLastModified(e.getTime());
                if (filename.equals("histLog.txt"))
                    dataTimeStamp = e.getTime();
                else
                    maxTimeStamp = Math.max(maxTimeStamp, e.getTime());
            }
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File)

Example 93 with ZipInputStream

use of java.util.zip.ZipInputStream in project processdash by dtuma.

the class WBSReplaceAction method extractChanges.

private File extractChanges(File srcFile) throws IOException {
    // create a temporary directory
    File extractDirectory = TempFileFactory.get().createTempDirectory("pdash-wbs-replace", ".tmp");
    // open the ZIP file
    InputStream in = new FileInputStream(srcFile);
    try {
        ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(in));
        ZipEntry e;
        while ((e = zipIn.getNextEntry()) != null) {
            if (!e.isDirectory()) {
                String filename = e.getName();
                File f = new File(extractDirectory, filename);
                if (filename.indexOf('/') != -1)
                    f.getParentFile().mkdirs();
                FileUtils.copyFile(zipIn, f);
            }
        }
    } finally {
        FileUtils.safelyClose(in);
    }
    // the settings.xml file in the replacement data might name a master
    // project. we don't need that information to perform the replacement
    // operation, and it would just slow down the loading of the replacement
    // team project; so we temporarily move that file out of the way.
    maybeRename(extractDirectory, SETTINGS_FILENAME, "X" + SETTINGS_FILENAME);
    return extractDirectory;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 94 with ZipInputStream

use of java.util.zip.ZipInputStream in project processdash by dtuma.

the class MigrationToolIndiv method restoreFromBackup.

private void restoreFromBackup() throws Exception {
    ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(new FileInputStream(extraBackupFile)));
    Exception exceptionEncountered = null;
    ZipEntry e;
    while ((e = zipIn.getNextEntry()) != null) {
        String name = e.getName();
        if (name.equals("log.txt") || name.indexOf('/') != -1 || name.indexOf('\\') != -1)
            continue;
        try {
            File f = file(name);
            FileUtils.copyFile(zipIn, f);
            f.setLastModified(e.getTime());
        } catch (Exception exc) {
            // if we encounter an exception on a particular file, try
            // to continue and restore the other files.  But record the
            // exception so we can pass it along.
            exceptionEncountered = exc;
        }
    }
    zipIn.close();
    if (exceptionEncountered != null)
        throw exceptionEncountered;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) FileInputStream(java.io.FileInputStream) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 95 with ZipInputStream

use of java.util.zip.ZipInputStream in project ddf by codice.

the class TestZipCompression method assertZipContents.

private void assertZipContents(BinaryContent binaryContent, List<String> ids) throws IOException {
    ZipInputStream zipInputStream = (ZipInputStream) binaryContent.getInputStream();
    List<String> entryNames = new ArrayList<>();
    ZipEntry zipEntry = zipInputStream.getNextEntry();
    while (zipEntry != null) {
        entryNames.add(zipEntry.getName());
        zipEntry = zipInputStream.getNextEntry();
    }
    assertThat(entryNames.size(), is(ids.size()));
    for (String id : ids) {
        assertThat(entryNames, hasItem(id));
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)968 ZipEntry (java.util.zip.ZipEntry)762 IOException (java.io.IOException)355 File (java.io.File)319 FileInputStream (java.io.FileInputStream)316 InputStream (java.io.InputStream)203 FileOutputStream (java.io.FileOutputStream)198 ByteArrayInputStream (java.io.ByteArrayInputStream)190 ByteArrayOutputStream (java.io.ByteArrayOutputStream)138 BufferedInputStream (java.io.BufferedInputStream)127 ZipOutputStream (java.util.zip.ZipOutputStream)91 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)80 OutputStream (java.io.OutputStream)67 URL (java.net.URL)58 Path (java.nio.file.Path)58 FileNotFoundException (java.io.FileNotFoundException)56 HashMap (java.util.HashMap)56 BufferedOutputStream (java.io.BufferedOutputStream)54 ZipFile (java.util.zip.ZipFile)43