本文整理了Java中org.openide.util.Utilities.toURI()
方法的一些代码示例,展示了Utilities.toURI()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.toURI()
方法的具体详情如下:
包路径:org.openide.util.Utilities
类名称:Utilities
方法名:toURI
[英]Converts a file to a URI while being safe for UNC paths. Unlike File#toURI the result works with URI#normalize()and URI#resolve(URI).
[中]将文件转换为URI,同时确保UNC路径的安全。与文件#toURI不同,结果与URI#normalize()和URI#resolve(URI)一起工作。
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
private static URL toURL(File fFile, FileObject fo) throws MalformedURLException {
URL retVal = Utilities.toURI(fFile).toURL();
if (retVal != null && fo.isFolder()) {
// #155742,160333 - URL for folder must always end with slash
final String urlDef = retVal.toExternalForm();
final String pathSeparator = "/";//NOI18N
if (!urlDef.endsWith(pathSeparator)) {
retVal = new URL(urlDef + pathSeparator);
}
}
return retVal;
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
private static File normalizeFileOnUnixAlike(File file) {
// On Unix, do not want to traverse symlinks.
// URI.normalize removes ../ and ./ sequences nicely.
file = Utilities.toFile(Utilities.toURI(file).normalize()).getAbsoluteFile();
while (file.getAbsolutePath().startsWith("/../")) { // NOI18N
file = new File(file.getAbsolutePath().substring(3));
}
if (file.getAbsolutePath().equals("/..")) { // NOI18N
// Special treatment.
file = new File("/"); // NOI18N
}
return file;
}
代码示例来源:origin: org.netbeans.api/org-openide-util
/**
* Convert a file to a matching <code>file:</code> URL.
* @param f a file (absolute only)
* @return a URL using the <code>file</code> protocol
* @throws MalformedURLException for no good reason
* @see #toFile
* @see <a href="http://www.netbeans.org/issues/show_bug.cgi?id=29711">Issue #29711</a>
* @since 3.26
* @deprecated Use {@link #toURI} and {@link URI#toURL} instead under JDK 1.4.
* ({@link File#toURL} is buggy in JDK 1.3 and the bugs are not fixed in JDK 1.4.)
*/
@Deprecated
public static URL toURL(File f) throws MalformedURLException {
if (f == null) {
throw new NullPointerException();
}
if (!f.isAbsolute()) {
throw new IllegalArgumentException("Relative path: " + f); // NOI18N
}
URI uri = toURI(f);
return uri.toURL();
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
private static File normalizeFileOnMac(final File file) {
File retVal = file;
try {
// URI.normalize removes ../ and ./ sequences nicely.
File absoluteFile = Utilities.toFile(Utilities.toURI(file).normalize());
File canonicalFile = file.getCanonicalFile();
String absolutePath = absoluteFile.getAbsolutePath();
if (absolutePath.equals("/..")) { // NOI18N
// Special treatment.
absoluteFile = new File(absolutePath = "/"); // NOI18N
}
boolean isSymLink = !canonicalFile.getAbsolutePath().equalsIgnoreCase(absolutePath);
if (isSymLink) {
retVal = normalizeSymLinkOnMac(absoluteFile);
} else {
retVal = canonicalFile;
}
} catch (IOException ioe) {
LOG.log(Level.FINE, "Normalization failed on file " + file, ioe);
// OK, so at least try to absolutize the path
retVal = file.getAbsoluteFile();
}
return retVal;
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
wasDir = entry.isDirectory();
LOG.finest("urlForArchiveOrDir:toURI:entry"); //NOI18N
u = Utilities.toURI(entry).toURL();
isDir = entry.isDirectory();
} while (wasDir ^ isDir);
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Finds appropriate FileObjects to java.io.File if possible.
* If not possible then empty array is returned. More FileObjects may
* correspond to one java.io.File that`s why array is returned.
* @param file File whose corresponding FileObjects will be looked for.
* The file has to be "normalized" otherwise IllegalArgumentException is thrown.
* See {@link #normalizeFile} for how to do that.
* @return corresponding FileObjects or empty array if no
* corresponding FileObject exists.
* @since 1.29
* @deprecated Use {@link #toFileObject} instead.
*/
@Deprecated
public static FileObject[] fromFile(File file) {
FileObject[] retVal;
if (!file.equals(normalizeFile(file))) {
throw new IllegalArgumentException(
"Parameter file was not " + // NOI18N
"normalized. Was " + toDebugString(file) + " instead of " + toDebugString(normalizeFile(file))); // NOI18N
}
try {
URL url = (Utilities.toURI(file).toURL());
retVal = URLMapper.findFileObjects(url);
} catch (MalformedURLException e) {
retVal = null;
}
return retVal;
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
URL url = Utilities.toURI(file).toURL();
retVal = URLMapper.findFileObject(url);
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
"jar:" + Utilities.toURI(new File(f,toReplace + fo.getPath())).toString().replaceFirst("/"+toReplace,"!/") + // NOI18N
((fo.isFolder() && !fo.isRoot()) ? "/" : "")
代码示例来源:origin: org.netbeans.api/org-openide-util-ui
/**
* Convert a file to a matching <code>file:</code> URL.
* @param f a file (absolute only)
* @return a URL using the <code>file</code> protocol
* @throws MalformedURLException for no good reason
* @see #toFile
* @see <a href="http://www.netbeans.org/issues/show_bug.cgi?id=29711">Issue #29711</a>
* @since 3.26
* @deprecated Use {@link #toURI} and {@link URI#toURL} instead under JDK 1.4.
* ({@link File#toURL} is buggy in JDK 1.3 and the bugs are not fixed in JDK 1.4.)
*/
@Deprecated
public static URL toURL(File f) throws MalformedURLException {
if (f == null) {
throw new NullPointerException();
}
if (!f.isAbsolute()) {
throw new IllegalArgumentException("Relative path: " + f); // NOI18N
}
URI uri = toURI(f);
return uri.toURL();
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-project-ant-ui
private boolean areCollocated(File base, Collection<File> files){
for(File file: files){
if (!CollocationQuery.areCollocated(Utilities.toURI(base), Utilities.toURI(file))) {
return false;
}
}
return true;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-cldcplatform
public static URL localfilepath2url(final String path) {
try {
return Utilities.toURI(new File(path)).toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-glassfish-javaee
private void addURL( Collection<URL> urls, File file ){
if ( file == null || !file.exists()) {
return;
}
try {
urls.add(Utilities.toURI(file).toURL());
} catch (MalformedURLException ex) {
// ignore the file
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-project
private BrandedFile(final BrandableModule moduleEntry, final URL source, final String entry) throws MalformedURLException {
this.moduleEntry = moduleEntry;
this.entryPath = entry;
if (source == null) {
brandingSource = Utilities.toURI(moduleEntry.getJarLocation()).toURL();
brandingSource = new URL("jar:" + brandingSource + "!/" + entryPath); // NOI18N
} else {
brandingSource = source;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject
public List<URL> getRootURLs() {
List<URL> urls = new ArrayList<>();
try {
for (FileObject fileObject : getRoots()) {
urls.add(Utilities.toURI(FileUtil.toFile(fileObject)).toURL());
}
} catch (MalformedURLException murle) {
Exceptions.printStackTrace(murle);
}
return urls;
}
代码示例来源:origin: net.sourceforge.javydreamercsw/Client-UI
protected ImageIcon createImage(String module_id, String path, String description)
throws Exception {
File icon = InstalledFileLocator.getDefault().locate(path,
"com.validation.manager.client.hierarchy", false);
URL imageURL = Utilities.toURI(icon).toURL();
if (imageURL == null) {
throw new Exception("Resource not found: " + path);
} else {
return new ImageIcon(imageURL, description);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-maven-indexer
private static @CheckForNull Document loadPluginXml(File jar) {
if (!jar.isFile() || !jar.getName().endsWith(".jar")) {
return null;
}
LOG.log(Level.FINER, "parsing plugin.xml from {0}", jar);
try {
return XMLUtil.parse(new InputSource("jar:" + Utilities.toURI(jar) + "!/META-INF/maven/plugin.xml"), false, false, XMLUtil.defaultErrorHandler(), null);
} catch (Exception x) {
LOG.log(Level.FINE, "could not parse " + jar, x.toString());
return null;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
private static String getFileNameUrl(PhpVariable variable) {
FileObject file = variable.getFile();
if (file != null && file.isValid()) {
try {
return Utilities.toURI(FileUtil.toFile(file)).toURL().toExternalForm();
} catch (MalformedURLException ex) {
Logger.getLogger(PhpElementCompletionItem.class.getName()).log(Level.WARNING, null, ex);
}
}
return null;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
private static void initDoc() {
File file = InstalledFileLocator.getDefault().locate("docs/predefined_vars.zip", null, true); //NoI18N
if (file != null) {
try {
URL urll = Utilities.toURI(file).toURL();
urll = FileUtil.getArchiveRoot(urll);
docURLBase = urll.toString();
} catch (java.net.MalformedURLException e) {
LOGGER.log(Level.FINE, null, e);
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl
public LayerDescriptor getDefault() {
File file = Places.getCacheSubdirectory("cnd/model"); // NOI18N
URI uri = Utilities.toURI(file);
LayerDescriptor layerDescriptor = new LayerDescriptor(uri);
return layerDescriptor;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-project
private void loadBrandedFiles(final BrandableModule mEntry,
final File file) throws IOException {
String entryPath = PropertyUtils.relativizeFile(getModuleEntryDirectory(mEntry),file);
BrandedFile bf = new BrandedFile(mEntry, Utilities.toURI(file).toURL(), entryPath);
brandedFiles.add(bf);
}
内容来源于网络,如有侵权,请联系作者删除!