本文整理了Java中com.thoughtworks.go.util.ZipUtil.zip()
方法的一些代码示例,展示了ZipUtil.zip()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipUtil.zip()
方法的具体详情如下:
包路径:com.thoughtworks.go.util.ZipUtil
类名称:ZipUtil
方法名:zip
暂无
代码示例来源: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
@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
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
@Before
public void setUp() throws Exception {
File folder = temporaryFolder.newFolder("log");
File consolelog = new File(folder, "console.log");
folder.mkdirs();
consolelog.createNewFile();
File uniqueTempFile = new File(folder, UUID.randomUUID().toString());
uniqueTempFile.createNewFile();
zip = new ZipUtil().zip(folder, uniqueTempFile, Deflater.NO_COMPRESSION);
}
代码示例来源: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 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
zipUtil.zip(file, dataToUpload, Deflater.BEST_SPEED);
代码示例来源:origin: gocd/gocd
zipUtil.zip(source, dataToUpload, Deflater.BEST_SPEED);
代码示例来源: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
@Before
public void setUp() throws Exception {
File folder = temporaryFolder.newFolder("log");
File consolelog = new File(folder, "console.log");
folder.mkdirs();
consolelog.createNewFile();
File uniqueTempFile = new File(folder, UUID.randomUUID().toString());
uniqueTempFile.createNewFile();
zip = new ZipUtil().zip(folder, uniqueTempFile, Deflater.NO_COMPRESSION);
toClean.add(folder);
toClean.add(zip);
dest = new File("dest");
dest.mkdirs();
toClean.add(dest);
clock = new TestingClock();
publisher = new StubGoPublisher();
checksumFileHandler = mock(ChecksumFileHandler.class);
urlService = mock(URLService.class);
downloadAction = mock(DownloadAction.class);
}
代码示例来源: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 shouldZipFileAndUnzipIt() 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 downloadDirWithChecksum() throws Exception {
File folder = temporaryFolder.newFolder("log");
Files.write(Paths.get(folder.getPath(), "a"), "content for a".getBytes());
Files.write(Paths.get(folder.getPath(), "b"), "content for b".getBytes());
File zip = new ZipUtil().zip(folder, temporaryFolder.newFile("log.zip"), Deflater.NO_COMPRESSION);
httpService.setupDownload("http://far.far.away/log.zip", zip);
httpService.setupDownload("http://far.far.away/log.zip.md5", "s/log/a=524ebd45bd7de3616317127f6e639bd6\ns/log/b=83c0aa3048df233340203c74e8a93d7d");
runBuild(downloadDir(map(
"url", "http://far.far.away/log.zip",
"dest", "dest",
"src", "s/log",
"checksumUrl", "http://far.far.away/log.zip.md5")), Passed);
File dest = new File(sandbox, "dest");
assertThat(console.output(), containsString(String.format("Saved artifact to [%s] after verifying the integrity of its contents", dest.getPath())));
assertThat(FileUtils.readFileToString(new File(dest, "log/a"), UTF_8), is("content for a"));
assertThat(FileUtils.readFileToString(new File(dest, "log/b"), UTF_8), is("content for b"));
}
内容来源于网络,如有侵权,请联系作者删除!