本文整理了Java中com.thoughtworks.go.util.ZipUtil
类的一些代码示例,展示了ZipUtil
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipUtil
类的具体详情如下:
包路径:com.thoughtworks.go.util.ZipUtil
类名称:ZipUtil
暂无
代码示例来源:origin: gocd/gocd
void explodePluginJarToBundleDir(File file, File location) {
try {
wipePluginBundleDirectory(location);
ZipUtil zipUtil = new ZipUtil();
zipUtil.unzip(file, location);
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to copy plugin jar %s to bundle location %s", file, location), e);
}
}
代码示例来源:origin: gocd/gocd
private void setOutput(boolean needToZip, File file, HttpServletResponse response) throws IOException {
ServletOutputStream out = response.getOutputStream();
if (needToZip) {
new ZipUtil().zip(file, out, Deflater.NO_COMPRESSION);
} else {
IOUtils.copy(new FileInputStream(file), out);
}
out.flush();
}
代码示例来源:origin: gocd/gocd
private boolean shouldReplaceBundledPlugins(File bundledPluginsDirectory) throws IOException {
File versionFile = new File(bundledPluginsDirectory, "version.txt");
if (!versionFile.exists()) return true;
String currentlyInstalledVersion = FileUtils.readFileToString(versionFile, UTF_8);
String versionNumberInZip = zipUtil.getFileContentInsideZip(getPluginsZipStream(), "version.txt");
return !currentlyInstalledVersion.equals(versionNumberInZip);
}
代码示例来源:origin: gocd/gocd
@Autowired
public AnalyticsPluginAssetsService(AnalyticsExtension analyticsExtension, AnalyticsMetadataLoader metadataLoader) {
this.zipUtil = new ZipUtil();
this.analyticsExtension = analyticsExtension;
this.pluginAssetPaths = new HashMap<>();
metadataLoader.registerListeners(this);
metadataStore = AnalyticsMetadataStore.instance();
}
代码示例来源:origin: gocd/gocd
public void unzip(File zip, File destDir) throws IOException {
unzip(new ZipInputStream(new BufferedInputStream(new FileInputStream(zip))), destDir);
}
代码示例来源:origin: gocd/gocd
@Test
@RunIf(value = OSChecker.class, arguments = OSChecker.LINUX)
public void shouldZipFileWhoseNameHasSpecialCharactersOnLinux() throws IOException {
File specialFile = new File(srcDir, "$`#?@!()?-_{}^'~.+=[];,a.txt");
FileUtils.writeStringToFile(specialFile, "specialFile", UTF_8);
zipFile = zipUtil.zip(srcDir, temporaryFolder.newFile(), Deflater.NO_COMPRESSION);
zipUtil.unzip(zipFile, destDir);
File baseDir = new File(destDir, srcDir.getName());
File actualSpecialFile = new File(baseDir, specialFile.getName());
assertThat(actualSpecialFile.isFile(), is(true));
assertThat(fileContent(actualSpecialFile), is(fileContent(specialFile)));
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldZipFileContentsOnly() throws IOException {
zipFile = zipUtil.zipFolderContents(srcDir, temporaryFolder.newFile(), Deflater.NO_COMPRESSION);
assertThat(zipFile.isFile(), is(true));
zipUtil.unzip(zipFile, destDir);
assertIsDirectory(new File(destDir, emptyDir.getName()));
assertIsDirectory(new File(destDir, childDir1.getName()));
File actual1 = new File(destDir, file1.getName());
assertThat(actual1.isFile(), is(true));
assertThat(fileContent(actual1), is(fileContent(file1)));
File actual2 = new File(destDir, childDir1.getName() + File.separator + file2.getName());
assertThat(actual2.isFile(), is(true));
assertThat(fileContent(actual2), is(fileContent(file2)));
}
代码示例来源:origin: gocd/gocd
@Override void createCachedFile(ArtifactFolder artifactFolder) throws IOException {
File originalFolder = artifactFolder.getRootFolder();
File cachedZip = cachedFile(artifactFolder);
File cachedTempZip = zipToTempFile(cachedZip);
cachedTempZip.getParentFile().mkdirs();
try {
zipUtil.zip(originalFolder, cachedTempZip, Deflater.DEFAULT_COMPRESSION);
} catch (IOException e) {
cachedTempZip.delete();
throw e;
}
FileUtils.moveFile(cachedTempZip, cachedZip);
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldReadContentsOfAFileWhichIsInsideAZip() throws Exception {
FileUtils.writeStringToFile(new File(srcDir, "some-file.txt"), "some-text-here", UTF_8);
zipFile = zipUtil.zip(srcDir, temporaryFolder.newFile(), Deflater.NO_COMPRESSION);
String someStuff = zipUtil.getFileContentInsideZip(new ZipInputStream(new FileInputStream(zipFile)), "some-file.txt");
assertThat(someStuff, is("some-text-here"));
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldZipMultipleFolderContentsAndExcludeRootDirectory() throws IOException {
File folderOne = temporaryFolder.newFolder("a-folder1");
FileUtils.writeStringToFile(new File(folderOne, "folder1-file1.txt"), "folder1-file1", UTF_8);
FileUtils.writeStringToFile(new File(folderOne, "folder1-file2.txt"), "folder1-file2", UTF_8);
File folderTwo = temporaryFolder.newFolder("a-folder2");
FileUtils.writeStringToFile(new File(folderTwo, "folder2-file1.txt"), "folder2-file1", UTF_8);
FileUtils.writeStringToFile(new File(folderTwo, "folder2-file2.txt"), "folder2-file2", UTF_8);
File targetZipFile = temporaryFolder.newFile("final1.zip");
ZipBuilder zipBuilder = zipUtil.zipContentsOfMultipleFolders(targetZipFile, true);
zipBuilder.add("folder-one", folderOne);
zipBuilder.add("folder-two", folderTwo);
zipBuilder.done();
assertContent(targetZipFile, "folder-one/folder1-file1.txt", "folder1-file1");
assertContent(targetZipFile, "folder-one/folder1-file2.txt", "folder1-file2");
assertContent(targetZipFile, "folder-two/folder2-file1.txt", "folder2-file1");
assertContent(targetZipFile, "folder-two/folder2-file2.txt", "folder2-file2");
}
代码示例来源:origin: gocd/gocd
public void zipFolderContents(File destDir, File destZipFile) throws IOException {
zipFolderContents(destDir, destZipFile, Deflater.BEST_SPEED);
}
代码示例来源:origin: gocd/gocd
public GoArtifactsManipulatorStub(List<Property> properties, List<String> consoleOuts, HttpService service) {
super(service, new URLService(), new ZipUtil());
this.properties = properties;
this.consoleOuts = consoleOuts;
}
代码示例来源:origin: gocd/gocd
void usePackagedCommandRepository(ZipInputStream zipInputStream, File defaultDirectory) throws IOException {
FileUtil.deleteDirectoryNoisily(defaultDirectory);
zipUtil.unzip(zipInputStream, defaultDirectory);
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldZipFileContentsAndUnzipIt() throws IOException {
zipFile = zipUtil.zip(srcDir, temporaryFolder.newFile(), Deflater.NO_COMPRESSION);
assertThat(zipFile.isFile(), is(true));
zipUtil.unzip(zipFile, destDir);
File baseDir = new File(destDir, srcDir.getName());
assertIsDirectory(new File(baseDir, emptyDir.getName()));
assertIsDirectory(new File(baseDir, childDir1.getName()));
File actual1 = new File(baseDir, file1.getName());
assertThat(actual1.isFile(), is(true));
assertThat(fileContent(actual1), is(fileContent(file1)));
File actual2 = new File(baseDir, childDir1.getName() + File.separator + file2.getName());
assertThat(actual2.isFile(), is(true));
assertThat(fileContent(actual2), is(fileContent(file2)));
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldPreserveFileTimestampWhileGeneratingTheZipFile() throws Exception {
File file = temporaryFolder.newFile("foo.txt");
file.setLastModified(1297989100000L); // Set this to any date in the past which is greater than the epoch
File zip = zipUtil.zip(file, temporaryFolder.newFile("foo.zip"), Deflater.DEFAULT_COMPRESSION);
ZipFile actualZip = new ZipFile(zip.getAbsolutePath());
ZipEntry entry = actualZip.getEntry(file.getName());
assertThat(entry.getTime(), is(file.lastModified()));
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldZipMultipleFolderContentsWhenNotExcludingRootDirectory() throws IOException {
File folderOne = temporaryFolder.newFolder("folder1");
FileUtils.writeStringToFile(new File(folderOne, "folder1-file1.txt"), "folder1-file1", UTF_8);
FileUtils.writeStringToFile(new File(folderOne, "folder1-file2.txt"), "folder1-file2", UTF_8);
File folderTwo = temporaryFolder.newFolder("folder2");
FileUtils.writeStringToFile(new File(folderTwo, "folder2-file1.txt"), "folder2-file1", UTF_8);
FileUtils.writeStringToFile(new File(folderTwo, "folder2-file2.txt"), "folder2-file2", UTF_8);
File targetZipFile = temporaryFolder.newFile("final2.zip");
ZipBuilder zipBuilder = zipUtil.zipContentsOfMultipleFolders(targetZipFile, false);
zipBuilder.add("folder-one", folderOne);
zipBuilder.add("folder-two", folderTwo);
zipBuilder.done();
assertContent(targetZipFile, "folder-one/folder1/folder1-file1.txt", "folder1-file1");
assertContent(targetZipFile, "folder-one/folder1/folder1-file2.txt", "folder1-file2");
assertContent(targetZipFile, "folder-two/folder2/folder2-file1.txt", "folder2-file1");
assertContent(targetZipFile, "folder-two/folder2/folder2-file2.txt", "folder2-file2");
}
代码示例来源:origin: gocd/gocd
public void handle(InputStream stream) throws IOException {
ZipInputStream zipInputStream = new ZipInputStream(stream);
LOG.info("[Agent Fetch Artifact] Downloading from '{}' to '{}'. Will read from Socket stream to compute MD5 and write to file", srcFile, destOnAgent.getAbsolutePath());
long before = System.currentTimeMillis();
new ZipUtil((entry, stream1) -> {
LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Handling the entry: '{}'", srcFile, destOnAgent.getAbsolutePath(), entry.getName());
new ChecksumValidator(artifactMd5Checksums).validate(getSrcFilePath(entry), md5Hex(stream1), checksumValidationPublisher);
}).unzip(zipInputStream, destOnAgent);
LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Took: {}ms", srcFile, destOnAgent.getAbsolutePath(), System.currentTimeMillis() - before);
}
代码示例来源:origin: gocd/gocd
private File createZip(String subDirectoryName) throws IOException {
File first = new File(artifactDest, "first");
FileUtils.writeStringToFile(first, "First File", UTF_8);
File second = new File(artifactDest, subDirectoryName + "/second");
FileUtils.writeStringToFile(second, "Second File", UTF_8);
new ZipUtil().zip(artifactDest, zip, 0);
return zip;
}
代码示例来源:origin: gocd/gocd
public GoArtifactsManipulatorStub(HttpService service) {
super(service, new URLService(), new ZipUtil());
properties = new ArrayList<>();
consoleOuts = new ArrayList<>();
}
代码示例来源:origin: gocd/gocd
public boolean saveFile(File dest, InputStream stream, boolean shouldUnzip, int attempt) {
String destPath = dest.getAbsolutePath();
try {
LOGGER.trace("Saving file [{}]", destPath);
if (shouldUnzip) {
zipUtil.unzip(new ZipInputStream(stream), dest);
} else {
systemService.streamToFile(stream, dest);
}
LOGGER.trace("File [{}] saved.", destPath);
return true;
} catch (IOException e) {
final String message = format("Failed to save the file to: [%s]", destPath);
if (attempt < GoConstants.PUBLISH_MAX_RETRIES) {
LOGGER.warn(message, e);
} else {
LOGGER.error(message, e);
}
return false;
} catch (IllegalPathException e) {
final String message = format("Failed to save the file to: [%s]", destPath);
LOGGER.error(message, e);
return false;
}
}
内容来源于网络,如有侵权,请联系作者删除!