org.openide.filesystems.FileUtil.getArchiveRoot()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中org.openide.filesystems.FileUtil.getArchiveRoot()方法的一些代码示例,展示了FileUtil.getArchiveRoot()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getArchiveRoot()方法的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
方法名:getArchiveRoot

FileUtil.getArchiveRoot介绍

[英]Returns a URL representing the root of an archive. Clients may need to first call #isArchiveFile(URL) to determine if the URL refers to an archive file.
[中]返回表示存档根目录的URL。客户端可能需要首先调用#isArchiveFile(URL)来确定URL是否引用了存档文件。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/**
 * Returns a FileObject representing the root folder of an archive.
 * Clients may need to first call {@link #isArchiveFile(FileObject)} to determine
 * if the file object refers to an archive file.
 * @param fo a ZIP- (or JAR-) format archive file
 * @return a virtual archive root folder, or null if the file is not actually an archive
 * @since 4.48
 */
public static FileObject getArchiveRoot(FileObject fo) {
  URL archiveURL = URLMapper.findURL(fo, URLMapper.EXTERNAL);
  if (archiveURL == null) {
    return null;
  }
  return URLMapper.findFileObject(getArchiveRoot(archiveURL));
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

} while (wasDir ^ isDir);
if (isArchiveFile(u) || entry.isFile() && entry.length() < 4) {
  return getArchiveRoot(u);
} else if (isDir) {
  assert u.toExternalForm().endsWith("/");    //NOI18N

代码示例来源:origin: org.codehaus.mevenide/nb-project

public FileObject[] getRoots() {
  if (file.exists()) {
    FileObject[] fos = new FileObject[1];
    fos[0] = FileUtil.getArchiveRoot(FileUtil.toFileObject(file));
    return fos;
  }
  return new FileObject[0];
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-sun-appsrv81

/** Return URL representation of the specified file. */
private static URL fileToUrl(File file) throws MalformedURLException {
  URL url = file.toURI().toURL();
  if (FileUtil.isArchiveFile(url)) {
    url = FileUtil.getArchiveRoot(url);
  }
  return url;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-sun-appsrv81

/** Return URL representation of the specified file. */
private static URL fileToUrl(File file) throws MalformedURLException {
  URL url = file.toURI().toURL();
  if (FileUtil.isArchiveFile(url)) {
    url = FileUtil.getArchiveRoot(url);
  }
  return url;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-sun-appsrv81

private URL fileToUrl(File file) throws MalformedURLException {
  URL url = file.toURI().toURL();
  if (FileUtil.isArchiveFile(url)) {
    url = FileUtil.getArchiveRoot(url);
  }
  return url;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javafx2-platform

private static List<URI> getFxSources(@NonNull final File javaHome) {
  try {
    final File f = new File (javaHome, FX_SOURCES);
    if (f.exists() && f.canRead()) {
      final URL url = FileUtil.getArchiveRoot(Utilities.toURI(f).toURL());
      final URI uri = url.toURI();
      return Collections.singletonList (uri);
    }
  } catch (MalformedURLException | URISyntaxException e) {
    Exceptions.printStackTrace(e);
  }
  return Collections.emptyList();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-spring-beans

private static ClassPath createClassPath(List<URL> roots) {
    List<URL> jarRootURLs = new ArrayList<URL>();
    for (URL url : roots) {
      // Workaround for #126307: ClassPath roots should be JAR root URL, not file URLs.
      if (FileUtil.getArchiveFile(url) == null) {
        // Not an archive root URL.
        url = FileUtil.getArchiveRoot(url);
      }
      jarRootURLs.add(url);
    }
    return ClassPathSupport.createClassPath((jarRootURLs.toArray(new URL[jarRootURLs.size()])));
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-cldcplatform

public FileObject resolveRelativePathToFileObject(final String path) {
  if (path == null  ||  path.length() <= 0) return null;
  File f;
  if (path.startsWith(PLATFORM_STRING_PREFIX))
    f = new File(homeFile, path.substring(PLATFORM_STRING_PREFIX.length()));
  else
    f = new File(path);
  f = FileUtil.normalizeFile(f);
  final FileObject fo = FileUtil.toFileObject(f);
  if (fo == null || !FileUtil.isArchiveFile(fo)) return fo;
  return FileUtil.getArchiveRoot(fo);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-cldcplatform

public URL resolveRelativePathToURL(final String path) {
  if (path == null  ||  path.length() <= 0) return null;
  try {
    final URL url = getURL(path);
    if (!FileUtil.isArchiveFile(url)) {
      final String s = url.toExternalForm();
      if (s.endsWith("/")) return url; //NOI18N
      return new URL(s + '/'); //NOI18N
    }
    return FileUtil.getArchiveRoot(url);
  } catch (MalformedURLException e) {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: org.codehaus.mevenide/nb-project

public FileObject getRootFolder() {
  FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(art.getFile()));
  if (fo != null) {
    return FileUtil.getArchiveRoot(fo);
  }
  return null;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-project-jsf

public static URL toResourceURL(URL resource) {
  if (FileUtil.isArchiveFile(resource)) {
    resource = FileUtil.getArchiveRoot(resource);
  } else if (!resource.toExternalForm().endsWith("/")) {
    try {
      resource = new URL(resource.toExternalForm()+"/");
    } catch (MalformedURLException mue) {
      ErrorManager.getDefault().notify(mue);
    }
  }
  return resource;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-glassfish-javaee

/**
 *
 * @param file
 * @return
 * @throws java.net.MalformedURLException
 */
public static URL fileToUrl(File file) throws MalformedURLException {
  File nfile = FileUtil.normalizeFile(file);
  URL url = nfile.toURI().toURL();
  if (FileUtil.isArchiveFile(url)) {
    url = FileUtil.getArchiveRoot(url);
  }
  return url;
}

代码示例来源: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.api/org-netbeans-modules-java-source-base

@NonNull
  private static URI toURI(@NonNull final Pair<File,String> path) {
    try {
      final URL root = FileUtil.getArchiveRoot(BaseUtilities.toURI(path.first()).toURL());
      return new URI(String.format(
        "%s%s", //NOI18N
        root.toExternalForm(),
        PATH_RT_JAR_IN_CT_SYM));
    } catch (MalformedURLException | URISyntaxException e) {
      throw new IllegalArgumentException(e);
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javaee-project

private void addToSourceGroups(File[] classpathEntries, List<SourceGroup> sourceGroups) {
    for (int i = 0; i < classpathEntries.length; i++) {
      FileObject file = FileUtil.toFileObject(classpathEntries[i]);
      if (file != null) {
        FileObject archiveFile = FileUtil.getArchiveRoot(file);
        if (archiveFile != null) {
          sourceGroups.add(ProjectUISupport.createLibrariesSourceGroup(archiveFile, file.getNameExt(), icon, icon));
        }
      }
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-ejbjarproject

private void checkLibraryFolder (FileObject fo) {
  if (!FileUtil.isArchiveFile(fo)) {
    return;
  }
  
  if (fo.getParent ().equals (libFolder)) {
    try {
      classPathModifier.addRoots(new URL[] {FileUtil.getArchiveRoot(fo.getURL())}, ProjectProperties.JAVAC_CLASSPATH);
    }
    catch (IOException e) {
      Exceptions.printStackTrace(e);
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-clientproject

private void checkLibraryFolder (FileObject fo) {
  if (!FileUtil.isArchiveFile(fo)) {
    return;
  }
  
  if (fo.getParent ().equals (libFolder)) {
    try {
      cpMod.getClassPathModifier().addRoots(new URL[] {FileUtil.getArchiveRoot(fo.getURL())}, ProjectProperties.JAVAC_CLASSPATH);
    } catch (IOException e) {
      Exceptions.printStackTrace(e);
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-project-jsf

public static void addLocalizedRoots(Project project, String[] jarName, String type) throws IOException {
  ArrayList jars = new ArrayList(jarName.length);
  for (int i = 0; i < jarName.length; i++) {
    File f = InstalledFileLocator.getDefault().locate(jarName[i], null, true);
    if (f != null) {
      URL root = FileUtil.getArchiveRoot(FileUtil.toFileObject(f)).getURL();
      if (!hasRootReference(project, root, type)) {
        jars.add(root);
      }
    }
  }
  addRootReferences(project, (URL[])jars.toArray(new URL[0]), type);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javaee-specs-support

@Override
public boolean isBundled( String classFqn ) {
  Library restapiLibrary = LibraryManager.getDefault().getLibrary(RESTAPI_LIBRARY);
  List<URL> urls = restapiLibrary.getContent("classpath");            // NOI18N
  for( URL url : urls ){
    FileObject root = URLMapper.findFileObject(url);
    if ( FileUtil.isArchiveFile(root)){
      root = FileUtil.getArchiveRoot(root);
    }
    String classFileObject = classFqn.replace('.', '/')+".class";   // NOI18N
    if ( root.getFileObject(classFileObject) != null ){
      return true;
    }
  }
  return false;
}

相关文章

微信公众号

最新文章

更多