本文整理了Java中com.thoughtworks.go.util.FileUtil.sha1Digest()
方法的一些代码示例,展示了FileUtil.sha1Digest()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.sha1Digest()
方法的具体详情如下:
包路径:com.thoughtworks.go.util.FileUtil
类名称:FileUtil
方法名:sha1Digest
暂无
代码示例来源:origin: gocd/gocd
protected static boolean isFileChanged(File file, String sha) {
try {
String currentHash = FileUtil.sha1Digest(file);
return !currentHash.equals(sha);
} catch (Exception e) {
return true;
}
}
代码示例来源:origin: gocd/gocd
public String url(String remoteHost, String workingUrl) throws IOException {
boolean fileExist = artifact.exists();
LOG.debug("Requesting the file [{}], exist? [{}]", artifact.getAbsolutePath(), fileExist);
if (fileExist && artifact.isFile()) {
String sha1 = FileUtil.sha1Digest(artifact);
return format("%s/%s/%s/%s?sha1=%s", remoteHost, "remoting", "files", workingUrl,
URLEncoder.encode(sha1, "UTF-8"));
} else {
return format("%s/%s/%s/%s", remoteHost, "remoting", "files", workingUrl);
}
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldCalculateSha1Digest() throws IOException {
File tempFile = temporaryFolder.newFile();
FileUtils.writeStringToFile(tempFile, "12345", UTF_8);
assertThat(FileUtil.sha1Digest(tempFile), is("jLIjfQZ5yojbZGTqxg2pY0VROWQ="));
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldDownloadWithURLContainsSHA1WhenFileExists() throws Exception {
File artifactOnAgent = new File(sandbox, "pipelines/cruise/foo/a.jar");
new File(sandbox, "pipelines/cruise/foo").mkdirs();
FileUtils.writeStringToFile(artifactOnAgent, "foobar", UTF_8);
String sha1 = java.net.URLEncoder.encode(FileUtil.sha1Digest(artifactOnAgent), "UTF-8");
httpService.setupDownload(format("%s/remoting/files/cruise/1/dev/1/windows/a.jar", new URLService().baseRemoteURL()), "content for url without sha1");
httpService.setupDownload(format("%s/remoting/files/cruise/1/dev/1/windows/a.jar?sha1=%s", new URLService().baseRemoteURL(), sha1), "content for url with sha1");
FetchArtifactBuilder builder = getBuilder(new JobIdentifier("cruise", -1, "1", "dev", "1", "windows", 1L), "a.jar", "foo", new FileHandler(new File("pipelines/cruise/foo/a.jar"), "a.jar"));
runBuilder(builder, JobResult.Passed);
assertThat(artifactOnAgent.isFile(), is(true));
assertThat(FileUtils.readFileToString(artifactOnAgent, UTF_8), is("content for url with sha1"));
}
代码示例来源:origin: gocd/gocd
@Test
public void downloadFileShouldAppendSha1IntoDownloadUrlIfDestFileAlreadyExists() throws IOException {
File dest = new File(sandbox, "bar.jar");
Files.write(Paths.get(dest.getPath()), "foobar".getBytes());
String sha1 = java.net.URLEncoder.encode(FileUtil.sha1Digest(dest), "UTF-8");
httpService.setupDownload("http://far.far.away/foo.jar", "content without sha1");
httpService.setupDownload("http://far.far.away/foo.jar?sha1=" + sha1, "content with sha1");
runBuild(downloadFile(map(
"url", "http://far.far.away/foo.jar",
"dest", "bar.jar")), Passed);
assertThat(console.output(), containsString("Saved artifact"));
assertThat(FileUtils.readFileToString(dest, UTF_8), is("content with sha1"));
}
}
代码示例来源:origin: gocd/gocd
url += "?sha1=" + URLEncoder.encode(FileUtil.sha1Digest(artifact), "UTF-8");
} catch (UnsupportedEncodingException e) {
LOG.error("Download error", e);
内容来源于网络,如有侵权,请联系作者删除!