本文整理匯總了Java中org.zeroturnaround.zip.ZipUtil.pack方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipUtil.pack方法的具體用法?Java ZipUtil.pack怎麽用?Java ZipUtil.pack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.zeroturnaround.zip.ZipUtil
的用法示例。
在下文中一共展示了ZipUtil.pack方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Override
public File write(Package pkg, File targetDirectory) {
PackageMetadata packageMetadata = pkg.getMetadata();
File tmpDir = TempFileUtils.createTempDirectory("skipper" + packageMetadata.getName()).toFile();
File rootPackageDir = new File(tmpDir,
String.format("%s-%s", packageMetadata.getName(), packageMetadata.getVersion()));
rootPackageDir.mkdir();
writePackage(pkg, rootPackageDir);
if (!pkg.getDependencies().isEmpty()) {
File packagesDir = new File(rootPackageDir, "packages");
packagesDir.mkdir();
for (Package dependencyPkg : pkg.getDependencies()) {
File packageDir = new File(packagesDir, dependencyPkg.getMetadata().getName());
packageDir.mkdir();
writePackage(dependencyPkg, packageDir);
}
}
File targetZipFile = PackageFileUtils.calculatePackageZipFile(pkg.getMetadata(), targetDirectory);
ZipUtil.pack(rootPackageDir, targetZipFile, true);
FileSystemUtils.deleteRecursively(tmpDir);
return targetZipFile;
}
示例2: createZipPackage
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
protected File createZipPackage() throws Exception {
logInfo("");
logInfo(CREATE_ZIP_START);
final String stageDirectoryPath = mojo.getDeploymentStageDirectory();
final File stageDirectory = new File(stageDirectoryPath);
final File zipPackage = new File(stageDirectoryPath.concat(ZIP_EXT));
if (!stageDirectory.exists()) {
logError(STAGE_DIR_NOT_FOUND);
throw new Exception(STAGE_DIR_NOT_FOUND);
}
ZipUtil.pack(stageDirectory, zipPackage);
logDebug(REMOVE_LOCAL_SETTINGS);
ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE);
logInfo(CREATE_ZIP_DONE + stageDirectoryPath.concat(ZIP_EXT));
return zipPackage;
}
示例3: compressZIP
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
/**
* Compress a list of WorkflowRevision into a ZIP archive
* @param workflowsList the list of workflows to compress
* @return a byte array corresponding to the archive containing the workflows
*/
public byte[] compressZIP(List<WorkflowRevision> workflowsList) {
if (workflowsList == null || workflowsList.size() == 0) {
return null;
}
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
Stream<ZipEntrySource> streamSources = workflowsList.stream()
.map(workflowRevision -> new ByteSource(getName(workflowRevision),
workflowRevision.getXmlPayload()));
ZipEntrySource[] sources = streamSources.toArray(size -> new ZipEntrySource[size]);
ZipUtil.pack(sources, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例4: compress
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
/****
*
* @param root
* @throws IOException
*/
public static byte[] compress(File root) throws IOException {
if (root.exists()) {
File zip = new File(Files.createTempDir(), "data.zip");
ZipUtil.pack(root, zip, new NameMapper() {
@Override
public String map(String name) {
// Filter out the socket files...
if (name.endsWith(".sock"))
return null;
else
return name;
}
});
byte[] data = Files.toByteArray(zip);
zip.delete();
return data;
} else {
_log.warn("no data to compress: " + root.toString());
return new byte[] {};
}
}
示例5: realExport
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private void realExport(IDatabaseConfiguration config, File zip,
boolean active) {
try {
if (active)
Database.close();
if (config instanceof DerbyConfiguration) {
File folder = DatabaseDir.getRootFolder(config.getName());
ZipUtil.pack(folder, zip);
} else if (config instanceof MySQLConfiguration) {
MySQLDatabaseExport export = new MySQLDatabaseExport(
(MySQLConfiguration) config, zip);
export.run();
}
} catch (Exception e) {
log.error("Export failed " + zip, e);
}
}
示例6: run
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Override
public void run() {
try {
IDatabase sourceDb = config.createInstance();
DerbyDatabase targetDb = createTemporaryDb();
DatabaseImport io = new DatabaseImport(sourceDb, targetDb);
io.run();
sourceDb.close();
targetDb.close();
ZipUtil.pack(targetDb.getDatabaseDirectory(), zolcaFile);
FileUtils.deleteDirectory(targetDb.getDatabaseDirectory());
success = true;
} catch (Exception e) {
success = false;
log.error("failed export MySQL database as zolca-File", e);
}
}
示例7: processResult
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
protected void processResult(IEvaluationTask task) {
String resultPath = task.getResultPath();
if (ServerRunner.doCompress()) {
String zipName = resultPath.substring(0, resultPath.length() - 2) + ".zip";
ZipUtil.pack(new File(resultPath), new File(zipName));
if (ServerRunner.doDelete()) {
try {
FileUtils.deleteDirectory(new File(resultPath));
} catch (IOException ex) {
Logger.getLogger(SingleTaskEvaluatorBase.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
示例8: test2
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Test(description = "Проверка чтения дерева логов")
public void test2() throws ParseException, IOException {
LogFilesStructure logFilesStructure = new LogFilesStructure();
String path = "c:\\temp\\";
Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2017-02-17");
HashMap<String, ArrayList<String>> logAfterDate = logFilesStructure.getLogAfterDate(date);
for (HashMap.Entry<String,ArrayList<String>> entry : logAfterDate.entrySet()){
for (String logPath : entry.getValue()) {
FileUtils.copyFileToDirectory(new File(logPath),new File(path+"Archive\\"+entry.getKey()+"//"));
// FileUtils.moveFileToDirectory(new File(logPath),new File(path+entry.getKey()+"//"),true);
}
}
ZipUtil.pack(new File(path+"Archive\\"),new File(path+"archive.zip"));
}
示例9: storeMd5s
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private void storeMd5s(Collection<Path> filePaths) throws IOException {
Path md5TempPath = appConfig.getBaseServerPath().resolve(MD5_TEMP_PATH);
filePaths.forEach(filePath -> {
try {
Path dirRelativeToBase = appConfig.getSyncPath().relativize(filePath.getParent());
Path md5FilePath = md5TempPath.resolve(dirRelativeToBase).resolve(filePath.getFileName() + ".md5");
Files.createDirectories(md5FilePath.getParent());
Files.write(md5FilePath, computeMd5(filePath));
} catch (IOException e) {
LOGGER.warn("Error while computing md5.");
LogUtil.stacktrace(LOGGER, e);
}
});
OnlyContentZipEntrySource[] zipEntries = Files.walk(md5TempPath)
.filter(not(Files::isDirectory))
.map(file -> {
Path relativeToBase = md5TempPath.relativize(file);
return new OnlyContentZipEntrySource(relativeToBase.toString(), file.toFile());
})
.toArray(OnlyContentZipEntrySource[]::new);
Path md5File = appConfig.getBaseServerPath().resolve(MD5_FILE);
ZipUtil.pack(zipEntries, md5File.toFile());
ftpStoreFile(MD5_FILE, Files.newInputStream(md5File));
}
示例10: backupCurrentFiles
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private void backupCurrentFiles() throws IOException {
LOGGER.info("Backing up previous data...");
OnlyContentZipEntrySource[] zipEntries = findLocalServerFiles().stream()
.map(file -> {
Path relativeToBase = appConfig.getBaseServerPath().relativize(file);
return new OnlyContentZipEntrySource(relativeToBase.toString(), file.toFile());
})
.toArray(OnlyContentZipEntrySource[]::new);
Path backupZip = appConfig.getBackupPath().resolve(BACKUP_FILE_ZIP);
ZipUtil.pack(zipEntries, backupZip.toFile());
LOGGER.info("Backed up previous data at '{}'.", backupZip);
}
示例11: zipSmallFiles
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private Path zipSmallFiles(Collection<Path> localServerFiles) {
List<Path> smallFiles = filterForSmallFiles(localServerFiles);
OnlyContentZipEntrySource[] smallFileZipEntries = smallFiles.stream()
.map(smallFile -> {
Path relativeToBase = appConfig.getBaseServerPath().relativize(smallFile);
return new OnlyContentZipEntrySource(relativeToBase.toString(), smallFile.toFile());
})
.toArray(OnlyContentZipEntrySource[]::new);
Path smallFilesZip = appConfig.getSyncPath().resolve(SMALL_FILES_ZIP);
ZipUtil.pack(smallFileZipEntries, smallFilesZip.toFile());
return smallFilesZip;
}
示例12: pack
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Override
protected void pack() throws Exception
{
LocalDateTime now = LocalDateTime.now( );
String dateFormat = now.format(formatter);
String srcFolder = backupStruct.getTargetPath( ) + File.separator + GRAYLOG_SCHEMA_NAME;
String dstFolder = backupStruct.getTargetPath( ) + File.separator + GRAYLOG_SCHEMA_NAME + dateFormat + ".zip";
ZipUtil.pack(new File(srcFolder), new File(dstFolder));
LOG.info("Graylog config backup completed");
FileUtils.deleteDirectory(new File(srcFolder));
}
示例13: createTask
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
if (MainApp.getZdsutils().isAuthenticated() && result.isPresent()) {
String targetId = result.get().getValue().getId();
String targetSlug = result.get().getValue().getSlug();
String pathDir = content.getFilePath ();
updateMessage(Configuration.getBundle().getString("ui.task.zip.label")+" : "+targetSlug+" "+Configuration.getBundle().getString("ui.task.pending.label")+" ...");
ZipUtil.pack(new File(pathDir), new File(pathDir + ".zip"));
updateMessage(Configuration.getBundle().getString("ui.task.import.label")+" : "+targetSlug+" "+Configuration.getBundle().getString("ui.task.pending.label")+" ...");
if(result.get().getValue().getType() == null) {
if(!MainApp.getZdsutils().importNewContent(pathDir+ ".zip", result.get().getKey())) {
throw new IOException();
}
} else {
if(!MainApp.getZdsutils().importContent(pathDir + ".zip", targetId, targetSlug, result.get().getKey())) {
throw new IOException();
}
}
updateMessage(Configuration.getBundle().getString("ui.task.content.sync")+" ...");
try {
MainApp.getZdsutils().getContentListOnline().clear();
MainApp.getZdsutils().initInfoOnlineContent("tutorial");
MainApp.getZdsutils().initInfoOnlineContent("article");
} catch (IOException e) {
logger.error("Echec de téléchargement des metadonnés des contenus en ligne", e);
}
}
return null;
}
};
}
示例14: merge
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@TaskAction
public void merge() throws IOException {
ModGradleExtension extension = this.getProject().getExtensions().getByType(ModGradleExtension.class);
File tempMerge = new File(Constants.CACHE_FILES, "tempMerge.jar");
File tempClean = new File(Constants.CACHE_FILES, "tempClean");
if (tempMerge.exists()) {
tempMerge.delete();
}
if (tempClean.exists()) {
FileUtils.deleteDirectory(tempClean);
}
processJar(Constants.MINECRAFT_CLIENT_MAPPED_JAR.get(extension), Constants.MINECRAFT_SERVER_MAPPED_JAR.get(extension), tempMerge);
ZipUtil.unpack(tempMerge, tempClean, name -> {
if (name.startsWith("net/minecraft") || name.startsWith("assets") || name.startsWith("log4j2.xml") || (name.endsWith(".class") && !name.contains("/"))) {
return name;
} else {
return null;
}
});
ZipUtil.pack(tempClean, Constants.MINECRAFT_MERGED.get(extension));
if (tempMerge.exists()) {
tempMerge.delete();
}
if (tempClean.exists()) {
FileUtils.deleteDirectory(tempClean);
}
}
示例15: zipPack
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
/**
* @description: 壓縮並返回zip路徑
* @author: chenshiqiang E-mail:[email protected]
* @param track
* @return
*/
public static String zipPack(Track track){
if(createXml(track) != null){
String trackPath = PathConstants.getTrackpath()
+ File.separator + track.getUniqueMack();
String zipPath = PathConstants.getExportpath()
+ File.separator + StringUtils.filterIllegalWords(track.getName())
+ ".tsa";
ZipUtil.pack(new File(trackPath), new File(zipPath), true);
return zipPath;
}
return null;
}