@Override public boolean exists() { return Resources.exists(resource); }
/** * Copies a file into a security configuration directory. * * <p>If the security configuration directory does exist it will be created. * * @deprecated As of GeoServer 2.6, replaced by @link {@link #getSecurity()} */ @Deprecated public void copyToSecurityDir(File f) throws IOException { Resource resource = getSecurity(); Resources.copy(f, resource); }
/** * Convenience method for non recursive listing * * @param dir parent directory * @param filter parent directory * @return filtered list */ public static List<Resource> list(Resource dir, Filter<Resource> filter) { return list(dir, filter, false); }
/** @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; }
Resources.directory(targetBackupFolder, !Resources.exists(targetBackupFolder)); final String mosaicUrlBase = mosaicCoverageStore.getURL(); final Resource mosaicIndexBase = Resources.fromURL(mosaicUrlBase); (Resources.directory(mosaicIndexBase) != null ? Resources.directory(mosaicIndexBase) : Resources.directory(mosaicIndexBase.parent()))); BackupUtils.dir(targetBackupFolder, mosaicBaseFolder.name()); if (Resources.exists(mosaicIndexBase)) { for (Entry<String, Filter<Resource>> entry : resources.entrySet()) { List<Resource> mosaicIndexerResources = Resources.list(mosaicIndexBase, entry.getValue(), true); && !FilenameUtils.getBaseName(res.name()) .equals(mosaicBaseFolder.name()) && Resources.exists(res) && Resources.canRead(res)) { final String relative = mosaicIndexBase Resource targetFtl = Resources.fromPath(relative, targetBackupFolder); Resources.copy(res.file(), targetFtl.parent());
@Test public void resourcesTest() throws IOException { Resource source = getResource(); Resource directory = getDirectory(); Resources.copy(source.file(), directory); Resource target = directory.get(source.name()); assertTrue(Resources.exists(target)); assertEquals(target.name(), source.name()); } }
/** * @param sourceBackupFolder * @param mosaicIndexBase * @param res * @throws IOException */ private boolean copyFile( final Resource sourceBackupFolder, final Resource mosaicIndexBase, Resource res, boolean overwrite) throws IOException { final String relative = sourceBackupFolder.dir().toURI().relativize(res.file().toURI()).getPath(); Resource targetFtl = Resources.fromPath(relative, mosaicIndexBase.parent()); if (!Resources.exists(targetFtl) || overwrite) { if (!targetFtl.parent().dir().exists()) { targetFtl.parent().dir().mkdirs(); } Resources.copy(res.file(), targetFtl.parent()); return true; } return false; } }
final String mosaicUrlBase = mosaicCoverageStore.getURL(); final Resource mosaicIndexBase = Resources.fromURL(mosaicUrlBase); Resources.list(sourceBackupFolder, resources.get("properties"), true); Resources.list(sourceBackupFolder, resources.get("info"), true)); && Resources.exists(res) && Resources.canRead(res)) { boolean result = copyFile(sourceBackupFolder, mosaicIndexBase, res, false); Resources.list(sourceBackupFolder, resources.get("templates"), true); if (Resources.exists(res) && Resources.canRead(res)) { boolean result = copyFile(sourceBackupFolder, mosaicIndexBase, res, true);
/** * Helper method to create all create/modify events caused by a rename/move operation. (delete * events must be created separately.) This method should be called just before the action takes * place in order to analyze the effects properly. * * <p>Rename/move causes children to be moved as well. * * @param src Resource being renamed * @param dest Target resource after renatmed * @return List of notification events covering all the modified Resources */ public static List<Event> createRenameEvents(Resource src, Resource dest) { List<Event> events = new ArrayList<Event>(); events.add( new ResourceNotification.Event( dest.path(), Resources.exists(dest) ? Kind.ENTRY_MODIFY : Kind.ENTRY_CREATE)); for (Resource child : Resources.listRecursively(src)) { Resource newChild = dest.get(child.path().substring(src.path().length() + 1)); events.add( new ResourceNotification.Event( newChild.path(), Resources.exists(newChild) ? Kind.ENTRY_MODIFY : Kind.ENTRY_CREATE)); } return events; } }
/** * Checks {@link Resource#getType()} and returns existing dir() if available, or null for {@link * Resource.Type#UNDEFINED} or {@link Resource.Type#RESOURCE}. * * <p>This approach is a reproduction of GeoServerDataDirectory findDataDir logic and will not * create a new directory. * * @see Resource#dir() * @param resource Resource indicated * @return File reference to existing directory, or null for an existing file (or if directory * does not exist) */ public static File directory(Resource resource) { return directory(resource, false); }
@Override public File getFile() throws IOException { return Resources.find(resource); }
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); delegate = Resources.fromPath(path); }
@Test public void testUploadRootExternalProps() throws Exception { // On a brand new data folder, the directory may not exists until the Importer has been // invoked the first time File dirFromProperties = Resources.directory(Resources.fromPath("props_uploads")); // Read the upload root folder and creates it if does not exists importer.getUploadRoot(); // Read the folder again... dirFromProperties = Resources.directory(Resources.fromPath("props_uploads")); // ... and ensure it is the same as defined on the .properties file assertEquals(dirFromProperties, importer.getUploadRoot()); // Let's now override the external folder through the Environment variable. This takes // precedence on .properties System.setProperty(Importer.UPLOAD_ROOT_KEY, "env_uploads"); // Let's check that the upload root is now different from the previous one... assertNotEquals(dirFromProperties, importer.getUploadRoot()); // ... but it is equal to the one defined through the Environment variable instead // Read the folder again... dirFromProperties = Resources.directory(Resources.fromPath("env_uploads")); // ... and ensure it is the same as defined on the .properties file assertEquals(dirFromProperties, importer.getUploadRoot()); }
@Test public void testDelete() throws Exception { Resource newRes = getDataDirectory().get("/mydir/mynewres"); Resources.copy(myRes, newRes); assertTrue(Resources.exists(newRes)); deleteAsServletResponse(RestBaseController.ROOT_PATH + "/resource/mydir/mynewres"); Assert.assertFalse(Resources.exists(newRes)); }
for (Resource child : Resources.listRecursively(resource)) { events.add(new ResourceNotification.Event(child.path(), kind)); while (parent != null && !Resources.exists(parent)) { events.add(new ResourceNotification.Event(parent.path(), kind)); parent = parent.parent();
/** * Returns the root of the directory which contains spatial data files, if the directory does * exist, null is returned. * * <p>This directory is called 'data', and is located directly under {@link #root()} */ public File findDataRoot() throws IOException { Resource directory = get("data"); return Resources.directory(directory); }
@Override public URI getURI() throws IOException { return Resources.find(resource).toURI(); }
/** * 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)); }