本文整理了Java中org.apache.commons.io.FileUtils.toURLs()
方法的一些代码示例,展示了FileUtils.toURLs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.toURLs()
方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:toURLs
[英]Converts each of an array of File
to a URL
.
Returns an array of the same size as the input.
[中]将File
数组中的每个数组转换为URL
。
返回与输入大小相同的数组。
代码示例来源:origin: commons-io/commons-io
@Test
public void testToURLs3a() throws Exception {
final File[] files = new File[0]; // empty array
final URL[] urls = FileUtils.toURLs(files);
assertEquals(0, urls.length);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void emptyManifest() throws Exception {
Manifest mf = new Manifest();
File jar = createJar(mf, "emptyManifest.jar");
URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar}));
assertThat(ManifestUtils.getPropertyValues(classloader, "foo")).isEmpty();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void singleManifest() throws Exception {
Manifest mf = new Manifest();
mf.getMainAttributes().putValue("foo", "bar");
mf.getMainAttributes().putValue("other", "value");
File jar = createJar(mf, "singleManifest.jar");
URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar}));
List<String> values = ManifestUtils.getPropertyValues(classloader, "foo");
assertThat(values).containsOnly("bar");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void manyManifests() throws Exception {
Manifest mf1 = new Manifest();
mf1.getMainAttributes().putValue("foo", "bar");
File jar1 = createJar(mf1, "manyManifests-one.jar");
Manifest mf2 = new Manifest();
mf2.getMainAttributes().putValue("foo", "otherbar");
File jar2 = createJar(mf2, "manyManifests-two.jar");
URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar1, jar2}));
List<String> values = ManifestUtils.getPropertyValues(classloader, "foo");
assertThat(values).containsOnly("bar", "otherbar");
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testToURLs1() throws Exception {
final File[] files = new File[]{
new File(getTestDirectory(), "file1.txt"),
new File(getTestDirectory(), "file2.txt"),
new File(getTestDirectory(), "test file.txt"),
};
final URL[] urls = FileUtils.toURLs(files);
assertEquals(files.length, urls.length);
assertTrue(urls[0].toExternalForm().startsWith("file:"));
assertTrue(urls[0].toExternalForm().contains("file1.txt"));
assertTrue(urls[1].toExternalForm().startsWith("file:"));
assertTrue(urls[1].toExternalForm().contains("file2.txt"));
// Test escaped char
assertTrue(urls[2].toExternalForm().startsWith("file:"));
assertTrue(urls[2].toExternalForm().contains("test%20file.txt"));
}
代码示例来源:origin: org.jbpm/jbpm-gwt-form-exporter-gwt
@Override
public URL translateForm(FormRepresentation form) throws TranslatorException {
FormRepresentationEncoder encoder = FormEncodingServerFactory.getEncoder();
try {
String json = encoder.encode(form);
File file = File.createTempFile("form-gwt-", ".json");
FileUtils.writeStringToFile(file, json);
return FileUtils.toURLs(new File[] { file })[0];
} catch (IOException e) {
throw new TranslatorException("Problem writing temporal file", e);
} catch (FormEncodingException e) {
throw new TranslatorException("Problem encoding form", e);
}
}
内容来源于网络,如有侵权,请联系作者删除!