/** * Write the contents of a stream to a new Resource inside a directory * * @param data data to write * @param directory parent directory to create the resource in * @param filename file name of the new resource * @throws IOException If data could not be copied into indicated location */ public static void copy(InputStream data, Resource directory, String filename) throws IOException { copy(data, directory.get(filename)); }
@Override public Resource parent() { return delegate.parent() == null ? null : new SerializableResourceWrapper(delegate.parent()); }
/** * return true if a write lock is hold by another file watcher * * @throws IOException */ public boolean hasForeignWriteLock() throws IOException { return Resources.exists(lockFile) && lockFile.lastmodified() != lockFileLastModified; }
@Override public boolean matches(Object item) { if (item instanceof Resource) { return ((Resource) item).getType() != Type.UNDEFINED; } return false; }
/** * Used to look up resources based on user provided path using the Data Directory as base * directory. * * <p>Convenience method for Resources.fromPath(resources.get(Paths.BASE), path) * * <p>See {@link Resources#fromPath(String, Resource)} */ public Resource fromPath(String path) { return Resources.fromPath(path, resources.get(Paths.BASE)); }
/** * Used to look up resources based on user provided url using the Data Directory as base * directory. * * <p>Convenience method for Resources.fromURL(resources.get(Paths.BASE), url) * * <p>See {@link Resources#fromURL(Resource, URL)} */ public Resource fromURL(URL url) { return Resources.fromURL(resources.get(Paths.BASE), url); }
/** * Path construction. * * @param path Items defining a Path * @return path Path used to identify a Resource */ public static String path(String... path) { return path(STRICT_PATH, path); }
/** * Sets the base directory. * * @param baseDirectory base of data directory used for file configuration files */ public void setBaseDirectory(File baseDirectory) { this.baseDirectory = baseDirectory; if (resources == ResourceStore.EMPTY) { resources = new FileSystemResourceStore(baseDirectory); } }
@Override public void addListener(ResourceListener listener) { getResourceNotificationDispatcher().addListener(path, listener); }
@Override public void removeListener(ResourceListener listener) { getResourceNotificationDispatcher().removeListener(path, listener); }
@Override public Resource get(String path) { path = Paths.valid(path); return new FileSystemResource(path); }
@Override public void removeListener(ResourceListener listener) { watcher.removeListener(path(), listener); }
@Override public void addListener(ResourceListener listener) { watcher.addListener(path(), listener); }
/** * Schedule delay used when tracking {@link #asResource(File)} files. * * <p>Access provided for test cases. */ public static void schedule(long delay, TimeUnit unit) { watcher.schedule(delay, unit); }
/** * return true if a write lock is hold by this file watcher * * @throws IOException */ public boolean hasWriteLock() throws IOException { return Resources.exists(lockFile) && lockFile.lastmodified() == lockFileLastModified; }
@Override public boolean matches(Object item) { if (item instanceof Resource) { Resource res = (Resource) item; return res.getType() == Type.RESOURCE; } return false; }
/** * Used to look up resources based on user provided url (or path) using the Data Directory as * base directory. * * <p>Convenience method for Resources.fromURL(resources.get(Paths.BASE), url) * * <p>See {@link Resources#fromURL(Resource, String)} */ public Resource fromURL(String url) { return Resources.fromURL(resources.get(Paths.BASE), url); }