Пример #1
0
 public int compare(Object o1, Object o2) {
   File f1 = (File) o1;
   File f2 = (File) o2;
   if (f1.isDirectory()) {
     if (f2.isDirectory()) {
       switch (mode) {
           // Filename or Type
         case 1:
         case 4:
           return sign
               * f1.getAbsolutePath()
                   .toUpperCase()
                   .compareTo(f2.getAbsolutePath().toUpperCase());
           // Filesize
         case 2:
           return sign * (new Long(f1.length()).compareTo(new Long(f2.length())));
           // Date
         case 3:
           return sign * (new Long(f1.lastModified()).compareTo(new Long(f2.lastModified())));
         default:
           return 1;
       }
     } else return -1;
   } else if (f2.isDirectory()) return 1;
   else {
     switch (mode) {
       case 1:
         return sign
             * f1.getAbsolutePath().toUpperCase().compareTo(f2.getAbsolutePath().toUpperCase());
       case 2:
         return sign * (new Long(f1.length()).compareTo(new Long(f2.length())));
       case 3:
         return sign * (new Long(f1.lastModified()).compareTo(new Long(f2.lastModified())));
       case 4:
         { // Sort by extension
           int tempIndexf1 = f1.getAbsolutePath().lastIndexOf('.');
           int tempIndexf2 = f2.getAbsolutePath().lastIndexOf('.');
           if ((tempIndexf1 == -1) && (tempIndexf2 == -1)) { // Neither have an extension
             return sign
                 * f1.getAbsolutePath()
                     .toUpperCase()
                     .compareTo(f2.getAbsolutePath().toUpperCase());
           }
           // f1 has no extension
           else if (tempIndexf1 == -1) return -sign;
           // f2 has no extension
           else if (tempIndexf2 == -1) return sign;
           // Both have an extension
           else {
             String tempEndf1 = f1.getAbsolutePath().toUpperCase().substring(tempIndexf1);
             String tempEndf2 = f2.getAbsolutePath().toUpperCase().substring(tempIndexf2);
             return sign * tempEndf1.compareTo(tempEndf2);
           }
         }
       default:
         return 1;
     }
   }
 }
Пример #2
0
  public String _fmodified(String args[]) throws Exception {
    verifyCommand(args, _fmodifiedHelp, null, 2, Integer.MAX_VALUE);

    long time = 0;
    Collection<String> names = new ArrayList<String>();
    for (int i = 1; i < args.length; i++) {
      Processor.split(args[i], names);
    }
    for (String name : names) {
      File f = new File(name);
      if (f.exists() && f.lastModified() > time) time = f.lastModified();
    }
    return "" + time;
  }
 protected void addPathFile(final File pathComponent) throws IOException {
   if (!this.pathComponents.contains(pathComponent)) {
     this.pathComponents.addElement(pathComponent);
   }
   if (pathComponent.isDirectory()) {
     return;
   }
   final String absPathPlusTimeAndLength =
       pathComponent.getAbsolutePath()
           + pathComponent.lastModified()
           + "-"
           + pathComponent.length();
   String classpath = AntClassLoader.pathMap.get(absPathPlusTimeAndLength);
   if (classpath == null) {
     JarFile jarFile = null;
     try {
       jarFile = new JarFile(pathComponent);
       final Manifest manifest = jarFile.getManifest();
       if (manifest == null) {
         return;
       }
       classpath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
     } finally {
       if (jarFile != null) {
         jarFile.close();
       }
     }
     if (classpath == null) {
       classpath = "";
     }
     AntClassLoader.pathMap.put(absPathPlusTimeAndLength, classpath);
   }
   if (!"".equals(classpath)) {
     final URL baseURL = AntClassLoader.FILE_UTILS.getFileURL(pathComponent);
     final StringTokenizer st = new StringTokenizer(classpath);
     while (st.hasMoreTokens()) {
       final String classpathElement = st.nextToken();
       final URL libraryURL = new URL(baseURL, classpathElement);
       if (!libraryURL.getProtocol().equals("file")) {
         this.log(
             "Skipping jar library "
                 + classpathElement
                 + " since only relative URLs are supported by this"
                 + " loader",
             3);
       } else {
         final String decodedPath = Locator.decodeUri(libraryURL.getFile());
         final File libraryFile = new File(decodedPath);
         if (!libraryFile.exists() || this.isInPath(libraryFile)) {
           continue;
         }
         this.addPathFile(libraryFile);
       }
     }
   }
 }
Пример #4
0
  /**
   * Read block from file.
   *
   * @param file - File to read.
   * @param off - Marker position in file to start read from if {@code -1} read last blockSz bytes.
   * @param blockSz - Maximum number of chars to read.
   * @param lastModified - File last modification time.
   * @return Read file block.
   * @throws IOException In case of error.
   */
  public static VisorFileBlock readBlock(File file, long off, int blockSz, long lastModified)
      throws IOException {
    RandomAccessFile raf = null;

    try {
      long fSz = file.length();
      long fLastModified = file.lastModified();

      long pos = off >= 0 ? off : Math.max(fSz - blockSz, 0);

      // Try read more that file length.
      if (fLastModified == lastModified && fSz != 0 && pos >= fSz)
        throw new IOException(
            "Trying to read file block with wrong offset: " + pos + " while file size: " + fSz);

      if (fSz == 0)
        return new VisorFileBlock(file.getPath(), pos, fLastModified, 0, false, EMPTY_FILE_BUF);
      else {
        int toRead = Math.min(blockSz, (int) (fSz - pos));

        byte[] buf = new byte[toRead];

        raf = new RandomAccessFile(file, "r");

        raf.seek(pos);

        int cntRead = raf.read(buf, 0, toRead);

        if (cntRead != toRead)
          throw new IOException(
              "Count of requested and actually read bytes does not match [cntRead="
                  + cntRead
                  + ", toRead="
                  + toRead
                  + ']');

        boolean zipped = buf.length > 512;

        return new VisorFileBlock(
            file.getPath(), pos, fSz, fLastModified, zipped, zipped ? zipBytes(buf) : buf);
      }
    } finally {
      U.close(raf, null);
    }
  }
Пример #5
0
  /**
   * Decides if the given source is newer than a class.
   *
   * @param source the source we may want to compile
   * @param cls the former class
   * @return true if the source is newer, false else
   * @throws IOException if it is not possible to open an connection for the given source
   * @see #getTimeStamp(Class)
   */
  protected boolean isSourceNewer(URL source, Class cls) throws IOException {
    long lastMod;

    // Special handling for file:// protocol, as getLastModified() often reports
    // incorrect results (-1)
    if (isFile(source)) {
      // Coerce the file URL to a File
      // See ClassNodeResolver.isSourceNewer for another method that replaces '|' with ':'.
      // WTF: Why is this done and where is it documented?
      String path = source.getPath().replace('/', File.separatorChar).replace('|', ':');
      File file = new File(path);
      lastMod = file.lastModified();
    } else {
      URLConnection conn = source.openConnection();
      lastMod = conn.getLastModified();
      conn.getInputStream().close();
    }
    long classTime = getTimeStamp(cls);
    return classTime + config.getMinimumRecompilationInterval() < lastMod;
  }
Пример #6
0
 long _getScopeTime() {
   long last = 0;
   for (File f : _initFlies) if (f.exists()) last = Math.max(last, f.lastModified());
   return last;
 }
Пример #7
0
 /** Retourne true si le fichier indiqué date de plus de 24h */
 private boolean outOfDate(File f) {
   return System.currentTimeMillis() - f.lastModified() > OUTOFDATE;
 }