public FileWatcher(File file) { this.resource = Files.asResource(file); }
/** @deprecated use {@link Resources#fromURL(Resource, String)} */ @Deprecated public File url(String url) { return Files.url(baseDirectory, url); }
@Override public boolean delete() { return Files.delete(file); }
/** * Easy to use file delete (works for both files and directories). * * <p>Recursively deletes the contents of the specified directory, and finally wipes out the * directory itself. For each file that cannot be deleted a warning log will be issued. * * @param file File to remove * @return true if any file present is removed */ public static boolean delete(File file) { if (file.isDirectory()) { emptyDirectory(file); } return file.delete(); }
/** * @param file * @deprecated Use Resource instead of File */ @Deprecated protected FileWatcher(File file) { this.resource = Files.asResource(file); this.path = resource.path(); }
public void setObject(String location) { if (location != null) { File dataDirectory = canonicalize(rootDir); File file = canonicalize(new File(location)); if (isSubfile(dataDirectory, file)) { File curr = file; String path = null; // paranoid check to avoid infinite loops while (curr != null && !curr.equals(dataDirectory)) { if (path == null) { path = curr.getName(); } else { path = curr.getName() + "/" + path; } curr = curr.getParentFile(); } location = "file:" + path; } else { File dataFile = Files.url(rootDir, location); if (dataFile != null && !dataFile.equals(file)) { // relative to the data directory, does not need fixing } else { location = "file://" + file.getAbsolutePath(); } } } delegate.setObject(location); }
allClean &= delete(files[i]); } else { if (!files[i].delete()) {
/** * @param file * @throws IOException * @deprecated Use {@link #dumpMasterPassword(Resource)} */ public boolean dumpMasterPassword(File file) throws IOException { return dumpMasterPassword(Files.asResource(file)); }
/** * Converts an absolute URL to a resource to be relative to the data directory if applicable. * * @return The relative path, or the original path if it does not contain the data directory */ protected String relativeDataFileURL(String url, Catalog catalog) { if (catalog == null) { return url; } File baseDirectory = catalog.getResourceLoader().getBaseDirectory(); File f = Files.url(baseDirectory, url); return f == null ? url : "file:" + Paths.convert(baseDirectory, f); }
@Override public boolean delete() { Lock lock = lock(); try { return Files.delete(file); } finally { lock.release(); } }
/** * Alternative to {@link GeoServerResourceLoader#find(String)} that supports absolute paths for * use in test cases. * * <p>If an absolute path is used the Resource implementation is provided by {@link * Files#asResource(File)}. * * @param configFileLocation * @return resource */ Resource getConfigFile(String configFileLocation) throws IOException { File file = new File(configFileLocation); if (file.isAbsolute()) { if (file.canRead()) { return Files.asResource(file); // used by test cases } else { throw new IOException("Cannot read file: " + file.getCanonicalPath()); } } return null; }
if (baseDirectory != null) { relFile = Files.url(baseDirectory, uriSpec); } else if (loader != null) {
@Override public boolean remove(String path) { path = Paths.valid(path); File file = Paths.toFile(baseDirectory, path); return Files.delete(file); }
/** * Creates resource from a path, if the path is relative it will return a resource relative to * the provided directory otherwise it will return a file based resource * * @param path relative or absolute path * @param relativeDir directory to which relative paths are relative * @return resource */ public static org.geoserver.platform.resource.Resource fromPath( String path, org.geoserver.platform.resource.Resource relativeDir) { File file = new File(path); if (file.isAbsolute()) { return Files.asResource(file); } else { return relativeDir.get(path.replace(File.separatorChar, '/')); } }
BufferedImage image, String formatName, File destinationFile, int dpi) throws IOException { if (!Files.delete(destinationFile)) { ConsoleManager.getInstance() .information(
/** @deprecated use {@link Resources#fromURL(Resource, String)} */ @Deprecated public static File url(File baseDirectory, String url) { Resource res = Resources.fromURL(asResource(baseDirectory), url); if (res == null) { return null; } File file = Resources.find(res); if (file == null) { return new File(baseDirectory, res.path()); } return file; }
/** * Used to look up a resource based on user provided url. * * <p>Supports * * <ul> * <li>Actual URL to external resource using http or ftp protocol - will return null * <li>Resource URL - will support resources from resource store * <li>File URL - will support absolute file references * <li>File URL - will support relative file references - this is deprecated, use resource: * instead * <li>Fake URLs - sde://user:pass@server:port - will return null. * </ul> * * @param baseDirectory base directory for resource: or relative file: paths * @param url the url * @return corresponding Resource */ public static Resource fromURL(Resource baseDirectory, URL url) { if (url.getProtocol().equalsIgnoreCase("resource")) { return baseDirectory.get(Paths.convert(url.getPath())); } else if (url.getProtocol().equalsIgnoreCase("file")) { return Files.asResource(URLs.urlToFile(url)); } else { return null; } }
return Files.asResource(URLs.urlToFile(new URL(url))); } catch (Exception e) { return Files.asResource(f); // if it's an absolute path, use it as such return baseDirectory.get(url); return Files.asResource(f); // fine return it as is return Files.asResource(file); // if it's an absolute path, use it as such
/** * Spring Resource is made relative to Data Directory if path is relative. * * @param resource Spring resource * @param store the Resource Store * @return Spring resource relative to Data Directory * @throws IOException */ public static org.springframework.core.io.Resource relative( org.springframework.core.io.Resource resource, ResourceStore store) throws IOException { File f = resource.getFile(); if (f != null) { if (!f.isAbsolute()) { // make relative to data directory -- or create file from resource store Resource res = store.get(Paths.convert(f.getPath())); return new SpringResourceAdaptor(res); } else { return new SpringResourceAdaptor(Files.asResource(f)); } } else { return resource; } }
@Override protected Resource getUndefined() { return Files.asResource(new File(folder.getRoot(), "NonTestUndef")); }