/** * 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); }
/** * Copies data 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(InputStream data, String filename) throws IOException { Resource resource = getSecurity(); Resources.copy(data, resource, filename); }
/** * 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)); }
/** * Copies data into the root workspaces configuration directory. * * <p>If the workspace configuration directory does exist it will be created * * @deprecated As of GeoServer 2.6, replaced by {@link #get(WorkspaceInfo, String...)} */ @Deprecated public void copyToWorkspacesDir(InputStream data, String filename) throws IOException { Resources.copy(data, getWorkspaces(), filename); }
/** * Copies data into a store configuration directory. * * <p>If the store configuration directory does exist it will be created * * @deprecated As of GeoServer 2.6, replaced by {@link #get(StoreInfo, String...)} */ public void copyToStoreDir(StoreInfo store, InputStream data, String filename) throws IOException { Resource directory = get(store); Resources.copy(data, directory, filename); }
/** * Copies a file into a feature type configuration directory. * * <p>If the resource directory does exist it will be created * * @deprecated As of GeoServer 2.6, replaced by {@link #get(ResourceInfo, String...)} */ @Deprecated public void copyToResourceDir(ResourceInfo resource, File file) throws IOException { Resource directory = get(resource); Resources.copy(file, directory); }
/** * Copies data into a workspace configuration directory. * * <p>If the workspace configuration directory does exist it will be created * * @deprecated As of GeoServer 2.6, replaced by {@link #get(WorkspaceInfo, String...)} */ @Deprecated public void copyToWorkspaceDir(WorkspaceInfo ws, InputStream data, String filename) throws IOException { Resource directory = get(ws); Resources.copy(data, directory, filename); }
/** * Copies data into a feature type configuration directory. * * <p>If the resource directory does exist it will be created * * @deprecated As of GeoServer 2.6, replaced by {@link #get(ResourceInfo, String...)} */ @Deprecated public void copyToResourceDir(ResourceInfo resource, InputStream data, String filename) throws IOException { Resource directory = get(resource); Resources.copy(data, directory, filename); }
/** * Copies a file into a workspace configuration directory. * * <p>If the workspace configuration directory does exist it will be created. * * @param ws Target workspace for copied file * @param file File to copy * @deprecated As of GeoServer 2.6, replaced by {@link #get(WorkspaceInfo, String...)} */ @Deprecated public void copyToWorkspaceDir(WorkspaceInfo ws, File file) throws IOException { Resource directory = get(ws); Resources.copy(file, directory); }
/** * Write the contents of a File to a new Resource with the same name inside a directory * * @param data data to write * @param directory parent directory to create the resource in * @throws IOException If file could not be copied into directory */ public static void copy(File data, Resource directory) throws IOException { String filename = data.getName(); try (InputStream in = new FileInputStream(data)) { copy(in, directory.get(filename)); } }
/** * Renames a resource by reading it and writing to the new resource, then deleting the old one. * This is not atomic. * * @param source Resource to rename * @param destination New resource location * @return true if successful, false if either the write or delete failed. */ public static boolean renameByCopy(Resource source, Resource destination) { try { copy(source, destination); return source.delete(); } catch (IOException e) { return false; } }
/** * Copies a file into a store configuration directory. * * <p>If the store configuration directory does exist it will be created * * @deprecated As of GeoServer 2.6, replaced by {@link #get(StoreInfo, String...)} */ @Deprecated public void copyToStoreDir(StoreInfo store, File file) throws IOException { Resource directory = get(path(store)); Resources.copy(file, directory); }
/** * Write the contents of a resource into another resource. Also supports directories * (recursively). * * @param data resource to read * @param destination resource to write to * @throws IOException If data could not be copied to destination */ public static void copy(Resource data, Resource destination) throws IOException { if (data.getType() == Type.DIRECTORY) { for (Resource child : data.list()) { copy(child, destination.get(child.name())); } } else { try (InputStream in = data.in()) { copy(in, destination); } } }
@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()); } }
public JDBCResourceStore( DataSource ds, JDBCResourceStoreProperties config, ResourceStore oldResourceStore) { this(ds, config); this.oldResourceStore = oldResourceStore; if (config.isImport()) { if (oldResourceStore != null) { try { Resource root = oldResourceStore.get(""); for (Resource child : root.list()) { if (!ArrayUtils.contains(config.getIgnoreDirs(), child.name())) { Resources.copy(child, get(child.name())); } } config.setImport(false); config.save(); } catch (IOException e) { throw new IllegalStateException(e); } } else { LOGGER.warning("Cannot import resources: no old resource store available."); } } }
@Override public void saveConfiguration(GeoServerResourceLoader resourceLoader) throws IOException { for (Resource configFile : getFileLocations()) { Resource targetDir = Files.asResource( resourceLoader.findOrCreateDirectory( Paths.convert(rl.get("/").dir(), configFile.parent().dir()))); Resources.copy(configFile.file(), targetDir); } }
@Override public void saveConfiguration(GeoServerResourceLoader resourceLoader) throws IOException { GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); for (Resource controlflow : getFileLocations()) { Resource targetDir = Files.asResource( resourceLoader.findOrCreateDirectory( Paths.convert( loader.getBaseDirectory(), controlflow.parent().dir()))); Resources.copy(controlflow.file(), targetDir); } }
@Test public void testOTFFontRegistration() throws IOException { // loading fonts causes Java to open a Channel on the file, but there is no way to // release it from client code, thus the test will fail to delete filse on Windows Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS); // in case this font is already on the machine we cannot run a meaningful test FontCache fontCache = FontCache.getDefaultInstance(); String fontName = "League Mono Regular"; Assume.assumeThat(fontCache.getFont(fontName), CoreMatchers.nullValue()); // copy over the font Resource styles = getDataDirectory().get("styles"); String fontFileName = "LeagueMono-Regular.otf"; try (InputStream is = WMSLifecycleHandlerTest.class.getResourceAsStream(fontFileName)) { assertNotNull(is); Resources.copy(is, styles, fontFileName); } // force a reset getGeoServer().reset(); // now the font should be in font cache Font theFont = fontCache.getFont(fontName); assertThat(fontCache.getAvailableFonts().toString(), theFont, CoreMatchers.notNullValue()); } }
@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)); }
@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()); } }