SortedSet<String> listFiles(Resource dir) { SortedSet<String> result = new TreeSet<String>(); List<Resource> dirs = dir.list(); for (Resource d : dirs) { if (d.getType() == Type.DIRECTORY && d.get(CONFIG_FILENAME).getType() == Type.RESOURCE) { result.add(d.name()); } } return result; }
/** * 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)); }
public static Resource createRandom(String prefix, String suffix, Resource dir) throws IOException { // Use only the file name from the supplied prefix prefix = (new File(prefix)).getName(); Resource res; do { UUID uuid = UUID.randomUUID(); String name = prefix + uuid + suffix; res = dir.get(name); } while (exists(res)); return res; }
/** loads the named entity config from persistence */ public C loadConfig(String name, MigrationHelper migrationHelper) throws IOException { Resource dir = getRoot().get(name); if (dir.getType() != Type.DIRECTORY) { return null; } XStreamPersister xp = persister(); if (migrationHelper != null) { migrationHelper.migrationPersister(xp); } return (C) loadConfigFile(dir, xp); }
@Override public Resource getResource() { if (keyStoreResource == null) { keyStoreResource = securityManager.security().get(DEFAULT_FILE_NAME); } return keyStoreResource; }
@Override public org.springframework.core.io.Resource createRelative(String relativePath) throws IOException { return new SpringResourceAdaptor(resource.get(relativePath)); }
/** saves a config file to the specified directly using the specified xstream persister */ void saveConfigFile( SecurityConfig config, Resource directory, String filename, XStreamPersister xp) throws IOException { xStreamPersist(directory.get(filename), config, xp); }
/** * 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)); } }
void saveMasterPasswordDigest(String masterPasswdDigest) throws IOException { OutputStream fout = security().get(MASTER_PASSWD_DIGEST_FILENAME).out(); try { IOUtils.write(masterPasswdDigest, fout); } finally { fout.close(); } }
/** removes the user group service config from persistence */ public void removeConfig(String name) throws IOException { getRoot().get(name).delete(); }
private void writeCurrentVersion() throws IOException { Resource security = security(); security.dir(); Resource properties = security.get(VERSION_PROPERTIES); Properties p = new Properties(); p.put(VERSION, CURR_VERSION.toString()); try (OutputStream os = properties.out()) { p.store( os, "Current version of the security directory. Do not remove or alter this file"); } }
/** reads a config file from the specified directly using the specified xstream persister */ SecurityConfig loadConfigFile(Resource directory, String filename, XStreamPersister xp) throws IOException { InputStream fin = directory.get(filename).in(); try { return xp.load(fin, SecurityConfig.class).clone(true); } finally { fin.close(); } }
private void copyResToDir(Resource r, Resource newDir) throws IOException { Resource newR = newDir.get(r.name()); try (InputStream in = r.in(); OutputStream out = newR.out()) { IOUtils.copy(in, out); } } }
/** The root configuration for the role service. */ public Resource getConfigRoot() throws IOException { return getSecurityManager().role().get(getName()); }
/** Saves master password config out directly, not during a password change. */ public void saveMasterPasswordConfig(MasterPasswordConfig config) throws IOException { xStreamPersist(security().get(MASTER_PASSWD_CONFIG_FILENAME), config, globalPersister()); this.masterPasswordConfig = new MasterPasswordConfig(config); }
public void handleServiceRemove(ServiceInfo service) { XStreamServiceLoader loader = findServiceLoader(service); try { Resource dir = service.getWorkspace() != null ? dir(service.getWorkspace()) : resourceLoader.get(Paths.BASE); dir.get(loader.getFilename()).delete(); } catch (Throwable t) { throw new RuntimeException(t); } }
private void renameRes(Resource r, String newName) { try { rl.move(r.path(), r.parent().get(newName).path()); } catch (Exception e) { throw new CatalogException(e); } }
private void moveResToDir(Resource r, Resource newDir) { try { rl.move(r.path(), newDir.get(r.name()).path()); } catch (Exception e) { throw new CatalogException(e); } }
public final void save(T service, GeoServer gs, Resource directory) throws Exception { String filename = getFilename(); Resource resource = directory == null ? resourceLoader.get(filename) : directory.get(filename); // using resource output stream makes sure we write on a temp file and them move try (OutputStream out = resource.out()) { XStreamPersister xp = xpf.createXMLPersister(); initXStreamPersister(xp, gs); xp.save(service, out); } }
@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()); } }