public FileWatcher(File file) { this.resource = Files.asResource(file); }
/** * @param file * @deprecated Use Resource instead of File */ @Deprecated protected FileWatcher(File file) { this.resource = Files.asResource(file); this.path = resource.path(); }
/** * @param file * @throws IOException * @deprecated Use {@link #dumpMasterPassword(Resource)} */ public boolean dumpMasterPassword(File file) throws IOException { return dumpMasterPassword(Files.asResource(file)); }
/** * 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; }
/** * 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, '/')); } }
/** @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")); }
@Override protected Resource getDirectory() { try { return Files.asResource(folder.newFolder("NonTestDir")); } catch (IOException e) { fail(); return null; } }
@Override protected Resource getResource() { try { return Files.asResource(folder.newFile("NonTestFile")); } catch (IOException e) { fail(); return null; } }
roleResource = Files.asResource(roleFile); } else { roleResource = getConfigRoot().get(fileName);
@Override protected Resource getResource(String path) throws Exception { File file = Paths.toFile(null, path); if (!file.isAbsolute()) { // in linux, an absolute path might appear relative if the root slash has been removed. // This can also occur with the root path if java.io.tmpdir is relative. String rootPath = folder.getRoot().getPath(); String rootPathWithoutSlash = rootPath.startsWith("/") ? rootPath.substring(1) : rootPath; if (path.contains(rootPathWithoutSlash)) { file = Paths.toFile(new File("/"), path); } else { file = Paths.toFile(folder.getRoot(), path); } } return Files.asResource(file); }
ftInfoReader.read(Files.asResource(ftInfoFile)); FeatureTypeInfo featureType = readFeatureType(ftInfoReader, featureTypeDirectory); if (featureType == null) {
File userFile = new File(fileName); if (userFile.isAbsolute()) { userResource = Files.asResource(userFile); } else { userResource = getConfigRoot().get(fileName);
void importCatalog(File catalogFile) throws FileNotFoundException, IOException, Exception { CatalogFactory factory = catalog.getFactory(); LegacyCatalogReader reader = new LegacyCatalogReader(); reader.read(Files.asResource(catalogFile)); // build all the catalog objects that can be read from the catalog.xml file importNamespaces(factory, reader.namespaces(), false); importNamespaces(factory, reader.isolatedNamespaces(), true); importStyles(factory, reader.styles()); importDataStores(factory, reader.dataStores()); importFormats(factory, reader.formats()); }
expect(secMgr.masterPasswordProvider()).andReturn(Files.asResource(mrPwdFolder)).anyTimes();
@Override protected Resource getDirectory() { try { return Files.asResource(folder.newFolder("NonTestDir")); } catch (IOException e) { fail(); return null; } }
@Override protected Resource getResource() { try { return Files.asResource(folder.newFile("NonTestFile")); } catch (IOException e) { fail(); return null; } }