JarResourceManager.java :  » Math » migen » uk » ac » lkl » common » util » Java Open Source

Java Open Source » Math » migen 
migen » uk » ac » lkl » common » util » JarResourceManager.java
package uk.ac.lkl.common.util;

import java.io.File;
import java.io.FilenameFilter;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

public class JarResourceManager extends ResourceManager {

    private FilenameFilter fileOnlyFilter = new FilenameFilter() {
  public boolean accept(File dir, String name) {
      File file = new File(dir, name);
      return file.isFile();
  }
    };
    
    JarResourceManager() {
  super();
    }

    public List<String> getResourceListing(String path,
      boolean includeDirectories, boolean stripPath) {
  URL url = getClass().getClassLoader().getResource(path);
  String urlPath = url.getPath();
  File file = new File(urlPath);
  String[] entries;
  if (includeDirectories)
      entries = file.list();
  else
      entries = file.list(fileOnlyFilter);
  return Arrays.asList(entries);
    }

    public static void main(String[] args) {
  JarResourceManager manager = new JarResourceManager();
  List<String> entries =
    manager.getResourceListing("uk/ac/lkl/migen/system", false,
      true);
  System.out.println(entries);
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.