/** * Take a Resource that possibly might use URLConnection caching * and turn it into one that doesn't. * @param resource the JarFileResource to obtain without URLConnection caching. * @return the non-caching resource */ public static Resource getNonCachingResource (Resource resource) { if (!(resource instanceof JarFileResource)) return resource; JarFileResource oldResource = (JarFileResource)resource; JarFileResource newResource = new JarFileResource(oldResource.getURL(), false); return newResource; }
try{return newResource(file_url).exists();} catch(Exception e) {LOG.ignore(e); return false;} boolean check=checkConnection(); c.setUseCaches(getUseCaches()); jar_file=c.getJarFile(); close_jar_file = !getUseCaches();
/** * Returns the last modified time */ @Override public long lastModified() { if (checkConnection() && _file!=null) { if (exists() && _entry!=null) return _entry.getTime(); return _file.lastModified(); } return -1; }
@Override public synchronized String[] list() if (isDirectory() && _list==null) list = listEntries(); close(); list = listEntries();
@Override public synchronized String[] list() if (isDirectory() && _list==null) list = listEntries(); release(); list = listEntries();
private List<String> listEntries () checkConnection(); jc.setUseCaches(getUseCaches()); jarFile=jc.getJarFile();
/** * Returns true if the represented resource is a container/directory. * If the resource is not a file, resources ending with "/" are * considered directories. */ @Override public boolean isDirectory() { return _urlString.endsWith("/") || exists() && _directory; }
/** * Return the length of the resource */ @Override public long length() { if (isDirectory()) return -1; if (_entry!=null) return _entry.getSize(); return -1; }
@Override public synchronized void close() { _exists=false; _list=null; _entry=null; _file=null; //if the jvm is not doing url caching, then the JarFiles will not be cached either, //and so they are safe to close if (!getUseCaches()) { if ( _jarFile != null ) { try { if (LOG.isDebugEnabled()) LOG.debug("Closing JarFile "+_jarFile.getName()); _jarFile.close(); } catch ( IOException ioe ) { LOG.ignore(ioe); } } } _jarFile=null; super.close(); }
return new JarFileResource(url, useCaches);
@Override public synchronized String[] list() if (isDirectory() && _list==null) list = listEntries(); release(); list = listEntries();
private List<String> listEntries () checkConnection(); jc.setUseCaches(getUseCaches()); jarFile=jc.getJarFile();
@Override public synchronized String[] list() if (isDirectory() && _list==null) list = listEntries(); close(); list = listEntries();
/** * Returns true if the represented resource is a container/directory. * If the resource is not a file, resources ending with "/" are * considered directories. */ @Override public boolean isDirectory() { return _urlString.endsWith("/") || exists() && _directory; }
/** * Return the length of the resource */ @Override public long length() { if (isDirectory()) return -1; if (_entry!=null) return _entry.getSize(); return -1; }
@Override public synchronized void release() { _list=null; _entry=null; _file=null; //if the jvm is not doing url caching, then the JarFiles will not be cached either, //and so they are safe to close if (!getUseCaches()) { if ( _jarFile != null ) { try { LOG.debug("Closing JarFile "+_jarFile.getName()); _jarFile.close(); } catch ( IOException ioe ) { LOG.ignore(ioe); } } } _jarFile=null; super.release(); }
return new JarFileResource(url, useCaches);
try{return newResource(file_url).exists();} catch(Exception e) {LOG.ignore(e); return false;} boolean check=checkConnection(); c.setUseCaches(getUseCaches()); jarFile=c.getJarFile();
@Override public synchronized String[] list() if (isDirectory() && _list==null) list = listEntries(); release(); list = listEntries();
/** * Take a Resource that possibly might use URLConnection caching * and turn it into one that doesn't. * @param resource * @return the non-caching resource */ public static Resource getNonCachingResource (Resource resource) { if (!(resource instanceof JarFileResource)) return resource; JarFileResource oldResource = (JarFileResource)resource; JarFileResource newResource = new JarFileResource(oldResource.getURL(), false); return newResource; }