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

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

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

FileUtil.isArchiveFile介绍

[英]Tests if a non existent path represents a file.
[中]测试不存在的路径是否表示文件。

代码示例

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

/**
 * Tests if a URL represents a JAR or ZIP archive.
 * If there is no such file object, the test is done by heuristic: any URL with an extension is
 * treated as an archive.
 * @param url a URL to a file
 * @return true if the URL seems to represent a ZIP-format archive
 * @since 4.48
 */
public static boolean isArchiveFile(URL url) {
  Parameters.notNull("url", url);  //NOI18N
  if ("jar".equals(url.getProtocol())) { //NOI18N
    //Already inside archive, return false
    return false;
  }
  FileObject fo = URLMapper.findFileObject(url);
  if ((fo != null) && !fo.isVirtual()) {
    if (LOG.isLoggable(Level.FINEST)) {
      LOG.log(Level.FINEST, "isArchiveFile_FILE_RESOLVED", fo); //NOI18N, used by FileUtilTest.testIsArchiveFileRace
    }
    return isArchiveFile(fo);
  } else {
    return isArchiveFile(url.getPath());
  }
}

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

isDir = entry.isDirectory();
} while (wasDir ^ isDir);
if (isArchiveFile(u) || entry.isFile() && entry.length() < 4) {
  return getArchiveRoot(u);
} else if (isDir) {

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

return isArchiveFile(fo.getPath());
return isArchiveFile(fo.getPath());
  b = isArchiveFile(fo.getPath());

代码示例来源: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: dcaoyuan/nbscala

public final void setJavadocFolders (List<URL> c) {
  assert c != null;
  List<URL> safeCopy = Collections.unmodifiableList (new ArrayList<URL> (c));
  for (Iterator<URL> it = safeCopy.iterator(); it.hasNext();) {
    URL url = it.next ();
    if (!"jar".equals (url.getProtocol()) && FileUtil.isArchiveFile(url)) {
      throw new IllegalArgumentException ("JavadocFolder must be a folder.");
    }
  }
  this.javadoc = safeCopy;
  this.firePropertyChange(PROP_JAVADOC_FOLDER, null, null);
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-j2me-cdc-platform

public final void setJavadocFolders (List<URL> c) {
  assert c != null;
  List<URL> safeCopy = Collections.unmodifiableList (new ArrayList<URL> (c));
  for (URL url : safeCopy ) {
    if (!"jar".equals (url.getProtocol()) && FileUtil.isArchiveFile(url)) {
      throw new IllegalArgumentException ("JavadocFolder must be a folder.");
    }
  }
  this.javadoc = safeCopy;
  this.firePropertyChange(PROP_JAVADOC_FOLDER, null, null);
}

代码示例来源: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-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.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.codehaus.mevenide/nb-project

static URL fileToURL(File file) {
  try {
    URL url;
    url = file.toURI().toURL();
    if (FileUtil.isArchiveFile(url)) {
      url = FileUtil.getArchiveRoot(url);
    }
    if  (!url.toExternalForm().endsWith("/")) { //NOI18N
      url = new URL(url.toExternalForm() + "/"); //NOI18N
    }
    return url;
  } catch (MalformedURLException ex) {
    ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
    return null;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject

static URL fileToURL(File file) {
  try {
    URL url;
    url = file.toURI().toURL();
    if (FileUtil.isArchiveFile(url)) {
      url = FileUtil.getArchiveRoot(url);
    }
    if  (!url.toExternalForm().endsWith("/")) { //NOI18N
      url = new URL(url.toExternalForm() + "/"); //NOI18N
    }
    return url;
  } catch (MalformedURLException ex) {
    ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
    return null;
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-j2me-cdc-platform

public FileObject resolveRelativePathToFileObject(String path) {
  if (path == null  ||  path.length () <= 0) return null;
  File f;
  if (path.startsWith (PLATFORM_STRING_PREFIX)){
    FileObject fo = URLMapper.findFileObject(installFolders.iterator().next());
    if (fo == null) return null;
    f = new File (FileUtil.toFile(fo), path.substring (PLATFORM_STRING_PREFIX.length ()));
  } else {
    f = new File (path);
    if (!f.exists()) return null;
  }
  f = FileUtil.normalizeFile (f);
  FileObject fo = FileUtil.toFileObject(f);
  if (fo == null || !FileUtil.isArchiveFile(fo)) return fo;
  return FileUtil.getArchiveRoot(fo);
}

代码示例来源: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-glassfish-javaee

@Override
public boolean isBundled( String classFqn ) {
  List<URL> urls = libraryProvider.getJerseyClassPathURLs();
  for( URL url : urls ){
    FileObject root = URLMapper.findFileObject(url);
    if ( FileUtil.isArchiveFile(root)){
      root = FileUtil.getArchiveRoot(root);
    }
    String path = classFqn.replace('.', '/')+".class";
    if ( root.getFileObject(path )!= null ){
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projects

private JavaSource getJavaSource(SourcePathProvider sp) {
  String[] roots = sp.getOriginalSourceRoots();
  List<FileObject> sourcePathFiles = new ArrayList<FileObject>();
  for (String root : roots) {
    FileObject fo = FileUtil.toFileObject (new java.io.File(root));
    if (fo != null && FileUtil.isArchiveFile (fo)) {
      fo = FileUtil.getArchiveRoot (fo);
    }
    sourcePathFiles.add(fo);
  }
  ClassPath bootPath = ClassPathSupport.createClassPath(new FileObject[] {});
  ClassPath classPath = ClassPathSupport.createClassPath(new FileObject[] {});
  ClassPath sourcePath = ClassPathSupport.createClassPath(sourcePathFiles.toArray(new FileObject[] {}));
  return JavaSource.create(ClasspathInfo.create(bootPath, classPath, sourcePath), new FileObject[] {});
}

代码示例来源: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;
}

相关文章

微信公众号

最新文章

更多