org.scijava.util.FileUtils.getAllVersions()方法的使用及代码示例

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

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

FileUtils.getAllVersions介绍

[英]Lists all versions of a given (possibly versioned) file name.
[中]列出给定(可能已版本化)文件名的所有版本。

代码示例

代码示例来源:origin: org.scijava/minimaven

private final void deleteVersions(final File directory, final String filename,
  final File excluding)
{
  final File[] versioned = FileUtils.getAllVersions(directory, filename);
  if (versioned == null) return;
  for (final File file : versioned) {
    if (file.equals(excluding)) continue;
    if (!file.getName().equals(filename)) {
      env.err.println("Warning: deleting '" + file + "'");
    }
    if (!file.delete()) {
      env.err.println("Warning: could not delete '" + file + "'");
    }
  }
}

代码示例来源:origin: sc.fiji/fiji-compat

public static void verify(byte[] bytecode, PrintStream out) {
  try {
    final File[] files = FileUtils.getAllVersions(new File(System.getProperty("ij.dir"), "jars"), "jruby.jar");
    final URL[] urls = new URL[files.length];
    for (int i = 0; i < urls.length; i++) urls[i] = files[i].toURI().toURL();
    ClassLoader loader = new URLClassLoader(urls);
    Class<?> readerClass = loader.loadClass("jruby.objectweb.asm.ClassReader");
    java.lang.reflect.Constructor<?> ctor = readerClass.getConstructor(new Class[] { bytecode.getClass() });
    Object reader = ctor.newInstance(bytecode);
    Class<?> checkerClass = loader.loadClass("jruby.objectweb.asm.util.CheckClassAdapter");
    java.lang.reflect.Method verify = checkerClass.getMethod("verify", new Class[] { readerClass, Boolean.TYPE, PrintWriter.class });
    verify.invoke(null, new Object[] { reader, false, new PrintWriter(out) });
  } catch(Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.scijava/minimaven

protected static JarClassLoader discoverJavac() throws IOException {
    final String ijDir = System.getProperty("ij.dir");
    if (ijDir == null) return null;
    final File jars = new File(ijDir, "jars");
    final File[] javacVersions = FileUtils.getAllVersions(jars, "javac.jar");
    if (javacVersions.length == 0) {
      System.err.println("No javac.jar found (looked in " + jars + ")!");
      return null;
    }
    long newest = Long.MIN_VALUE;
    File javac = null;
    for (final File file : javacVersions) {
      final long mtime = file.lastModified();
      if (newest < mtime) {
        newest = mtime;
        javac = file;
      }
    }
    return new JarClassLoader(javac == null ? null : javac.getPath());
  }
}

代码示例来源:origin: sc.fiji/fiji-compat

@Override
public void run() {
  if (alreadyPatched || "false".equals(System.getProperty("patch.ij1")))
    return;
  try {
    String ijDirProperty = System.getProperty("imagej.dir");
    if (ijDirProperty == null) ijDirProperty = System.getProperty("ij.dir");
    final File jars = ijDirProperty == null ? null : new File(ijDirProperty, "jars");
    if (jars == null || FileUtils.getAllVersions(jars, "imagej-legacy.jar").length > 0) {
      LegacyInjector.preinit();
      ij1PatcherFound = true;
    }
    else if (FileUtils.getAllVersions(jars, "ij-legacy.jar").length > 0) try {
      Thread.currentThread().setContextClassLoader(
          getClass().getClassLoader());
      fallBackToPreviousLegacyEnvironment(ClassPool.getDefault());
    }
    catch (Throwable t) {
      t.printStackTrace();
      throw new NoClassDefFoundError();
    }
    else {
      throw new NoClassDefFoundError();
    }
  } catch (NoClassDefFoundError e) {
    fallBackToPreviousPatcher();
  }
  alreadyPatched = true;
}

代码示例来源:origin: scijava/scijava-common

@Test
public void testGetAllVersions() throws IOException {
  final String withClassifier = "miglayout-3.7.3.1-swing.jar";
  final String withoutClassifier = "miglayout-3.7.3.1.jar";
  final File tmp = createTemporaryDirectory("delete-other-");
  try {
    writeEmptyFile(new File(tmp, withClassifier));
    writeEmptyFile(new File(tmp, withoutClassifier));
    assertArrayEquals(new File[] { new File(tmp, withClassifier) },
      FileUtils.getAllVersions(tmp, withClassifier));
    assertArrayEquals(new File[] { new File(tmp, withoutClassifier) },
      FileUtils.getAllVersions(tmp, withoutClassifier));
  }
  finally {
    FileUtils.deleteRecursively(tmp);
  }
}

代码示例来源:origin: net.imagej/imagej-updater

final File[] versions = FileUtils.getAllVersions(
    correctVersion.getParentFile(),
    correctVersion.getName());

相关文章