Esempio n. 1
0
  public AudioInfo(String fname) {
    super(fname);

    String type = MimeType.getTypeFromFilename(fname);
    if (type.endsWith("/mpeg")) {
      setupMPEG(fname);
    } else if (type.endsWith("/ogg-vorbis")) {
      setupVORBIS(fname);
    } else if (type.endsWith("/x-wav")) {
      setupWAV(fname);
    }
  }
Esempio n. 2
0
  public static Info get(String fname) throws IOException {
    File f = new File(fname);
    String pname = f.getCanonicalPath();

    CacheEntry ce = (CacheEntry) infoCache.get(pname);
    long timestamp = f.lastModified();

    // see if cache entry valid
    if (ce != null && ce.timestamp == timestamp) {
      if (log.isDebugEnabled()) {
        log.debug("pull info (" + ce.info + ") from cache (" + ce + ") for " + pname);
      }
      return ce.info;
    }

    // determine type of info
    String type = MimeType.getTypeFromFilename(pname);
    if (type == null) {
      return null;
    }

    // get info
    Info info = null;
    if (type.startsWith("audio/")) {
      info = new AudioInfo(pname);
    } else if (type.startsWith("image/")) {
      info = new ImageInfo(pname);
    }

    // cache it
    if (info != null) {
      ce = new CacheEntry();
      ce.info = info;
      ce.timestamp = timestamp;
      infoCache.put(pname, ce);

      if (log.isDebugEnabled()) {
        log.debug("cached (" + ce + ") info (" + info + ") for " + pname);
      }
    }

    return info;
  }