本文整理了Java中groovy.lang.GroovyClassLoader.decodeFileName()
方法的一些代码示例,展示了GroovyClassLoader.decodeFileName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroovyClassLoader.decodeFileName()
方法的具体详情如下:
包路径:groovy.lang.GroovyClassLoader
类名称:GroovyClassLoader
方法名:decodeFileName
[英]This method will take a file name and try to "decode" any URL encoded characters. For example if the file name contains any spaces this method call will take the resulting %20 encoded values and convert them to spaces.
This method was added specifically to fix defect: Groovy-1787. The defect involved a situation where two scripts were sitting in a directory with spaces in its name. The code would fail when the class loader tried to resolve the file name and would choke on the URLEncoded space values.
[中]此方法将获取文件名并尝试“解码”任何URL编码字符。例如,如果文件名包含任何空格,则此方法调用将获取生成的%20编码值并将其转换为空格。
此方法专门用于修复缺陷:Groovy-1787。该缺陷涉及两个脚本位于名称中带有空格的目录中的情况。当类加载器试图解析文件名时,代码将失败,并将阻塞URLCoded的空间值。
代码示例来源:origin: org.codehaus.groovy/groovy
private static File fileReallyExists(URL ret, String fileWithoutPackage) {
File path;
try {
/* fix for GROOVY-5809 */
path = new File(ret.toURI());
} catch(URISyntaxException e) {
path = new File(decodeFileName(ret.getFile()));
}
path = path.getParentFile();
if (path.exists() && path.isDirectory()) {
File file = new File(path, fileWithoutPackage);
if (file.exists()) {
// file.exists() might be case insensitive. Let's do
// case sensitive match for the filename
File parent = file.getParentFile();
for (String child : parent.list()) {
if (child.equals(fileWithoutPackage)) return file;
}
}
}
//file does not exist!
return null;
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
private File getFileForUrl(URL ret, String filename) {
String fileWithoutPackage = filename;
if (fileWithoutPackage.indexOf('/') != -1) {
int index = fileWithoutPackage.lastIndexOf('/');
fileWithoutPackage = fileWithoutPackage.substring(index + 1);
}
File path = new File(decodeFileName(ret.getFile())).getParentFile();
if (path.exists() && path.isDirectory()) {
File file = new File(path, fileWithoutPackage);
if (file.exists()) {
// file.exists() might be case insensitive. Let's do
// case sensitive match for the filename
File parent = file.getParentFile();
String[] files = parent.list();
for (int j = 0; j < files.length; j++) {
if (files[j].equals(fileWithoutPackage)) return file;
}
}
}
//file does not exist!
return null;
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
private File fileReallyExists(URL ret, String fileWithoutPackage) {
File path;
try {
/* fix for GROOVY-5809 */
path = new File(ret.toURI());
} catch(URISyntaxException e) {
path = new File(decodeFileName(ret.getFile()));
}
path = path.getParentFile();
if (path.exists() && path.isDirectory()) {
File file = new File(path, fileWithoutPackage);
if (file.exists()) {
// file.exists() might be case insensitive. Let's do
// case sensitive match for the filename
File parent = file.getParentFile();
for (String child : parent.list()) {
if (child.equals(fileWithoutPackage)) return file;
}
}
}
//file does not exist!
return null;
}
代码示例来源:origin: org.kohsuke.droovy/groovy
private URL getSourceFile(String name) {
String filename = name.replace('.', '/') + config.getDefaultScriptExtension();
URL ret = getResource(filename);
if (ret != null && ret.getProtocol().equals("file")) {
String fileWithoutPackage = filename;
if (fileWithoutPackage.indexOf('/') != -1) {
int index = fileWithoutPackage.lastIndexOf('/');
fileWithoutPackage = fileWithoutPackage.substring(index + 1);
}
File path = new File(decodeFileName(ret.getFile())).getParentFile();
if (path.exists() && path.isDirectory()) {
File file = new File(path, fileWithoutPackage);
if (file.exists()) {
// file.exists() might be case insensitive. Let's do
// case sensitive match for the filename
File parent = file.getParentFile();
String[] files = parent.list();
for (int j = 0; j < files.length; j++) {
if (files[j].equals(fileWithoutPackage)) return ret;
}
}
}
//file does not exist!
return null;
}
return ret;
}
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
private URL getSourceFile(String name) {
String filename = name.replace('.', '/') + config.getDefaultScriptExtension();
URL ret = getResource(filename);
if (ret != null && ret.getProtocol().equals("file")) {
String fileWithoutPackage = filename;
if (fileWithoutPackage.indexOf('/') != -1) {
int index = fileWithoutPackage.lastIndexOf('/');
fileWithoutPackage = fileWithoutPackage.substring(index + 1);
}
File path = new File(decodeFileName(ret.getFile())).getParentFile();
if (path.exists() && path.isDirectory()) {
File file = new File(path, fileWithoutPackage);
if (file.exists()) {
// file.exists() might be case insensitive. Let's do
// case sensitive match for the filename
File parent = file.getParentFile();
String[] files = parent.list();
for (int j = 0; j < files.length; j++) {
if (files[j].equals(fileWithoutPackage)) return ret;
}
}
}
//file does not exist!
return null;
}
return ret;
}
内容来源于网络,如有侵权,请联系作者删除!