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);
}
}
}
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());
}
}
}
}
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;
}
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;
}
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));
}
}
Aggregations