List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:org.bonitasoft.web.designer.workspace.WorkspaceTest.java
@Test public void should_copy_widget_file_if_it_is_already_in_widget_repository_folder_with_a_former_version() throws Exception { mockWidgetsBasePath(Paths.get("src/test/resources/workspace/widgets")); //We create the widget files Path labelDir = temporaryFolder.newFolderPath("widgets", "pbLabel"); Path labelFile = labelDir.resolve("pbLabel.json"); byte[] fileContent = "{\"id\":\"pbLabel\", \"template\": \"<div>Hello</div>\", \"designerVersion\": \"1.0.1\"}" .getBytes(StandardCharsets.UTF_8); write(labelFile, fileContent, StandardOpenOption.CREATE); workspace.initialize();// w ww . j av a 2s . co m String newLabelContent = new String( readAllBytes(pathResolver.getWidgetsRepositoryPath().resolve("pbLabel/pbLabel.json"))); String oldLabelContent = new String( readAllBytes(Paths.get("src/test/resources/workspace/widgets/pbLabel/pbLabel.json"))); assertThat(newLabelContent).isNotEqualTo(oldLabelContent); }
From source file:org.apache.taverna.robundle.manifest.PathMetadata.java
public void setFile(Path file) { this.file = file; Path root = this.file.resolve("/"); URI uri = ROOT.resolve(root.toUri().relativize(file.toUri())); setUri(uri);/*from w ww .j a v a 2s. com*/ }
From source file:io.sledge.core.impl.installer.SledgePackageConfigurer.java
private void deleteZipFile(Path directory, String packageName) throws IOException { Path currentDir = directory.resolve(packageName); Files.deleteIfExists(currentDir); }
From source file:org.osiam.OsiamHome.java
private void copyToHome(Resource resource, Path osiamHomeDir) throws IOException { String pathUnderHome = resource.getURL().toString().replaceFirst(".*home/", ""); Path target = osiamHomeDir.resolve(pathUnderHome); Files.createDirectories(target.getParent()); Files.copy(resource.getInputStream(), target, StandardCopyOption.REPLACE_EXISTING); }
From source file:ee.ria.xroad.confproxy.util.ConfProxyHelper.java
/** * Deletes outdated previously generated global configurations from configuration target path * e.g. /var/lib/xroad/public, as defined by the 'validity interval' configuration proxy property. * @param conf the configuration proxy instance configuration * @throws IOException//from w w w. ja v a 2 s . c om * in case an old global configuration could not be deleted */ public static void purgeOutdatedGenerations(final ConfProxyProperties conf) throws IOException { Path instanceDir = Paths.get(conf.getConfigurationTargetPath()); log.debug("Create directories {}", instanceDir); Files.createDirectories(instanceDir); //avoid errors if it's not present for (String genTime : subDirectoryNames(instanceDir)) { Date current = new Date(); Date old; try { old = new Date(Long.parseLong(genTime)); } catch (NumberFormatException e) { log.error("Unable to parse directory name {}", genTime); continue; } long diffSeconds = TimeUnit.MILLISECONDS.toSeconds((current.getTime() - old.getTime())); long timeToKeep = Math.min(MAX_CONFIGURATION_LIFETIME_SECONDS, conf.getValidityIntervalSeconds()); if (diffSeconds > timeToKeep) { Path oldPath = Paths.get(conf.getConfigurationTargetPath(), genTime); FileUtils.deleteDirectory(oldPath.toFile()); log.debug("Purge directory {}", oldPath); } else { Path valid = instanceDir.resolve(genTime); log.debug("A valid generated configuration exists in '{}'", valid); } } }
From source file:fr.duminy.jbackup.core.archive.FileCollectorTest.java
private void addSymbolicLink(String parentDirName, String targetName) throws IOException { Path parentDir = (parentDirName == null) ? directory : directory.resolve(parentDirName); Path targetPath = parentDir.resolve(targetName); Path linkPath = parentDir.resolve("LinkTo" + targetName); Files.createSymbolicLink(linkPath, targetPath); }
From source file:com.boundlessgeo.geoserver.bundle.BundleExporterTest.java
@Test public void testBundleInfo() throws Exception { new CatalogCreator(cat).workspace("foo"); exporter = new BundleExporter(cat, new ExportOpts(cat.getWorkspaceByName("foo")).name("blah")); Path root = exporter.run(); assertPathExists(root, "bundle.json"); try (FileInputStream in = new FileInputStream(root.resolve("bundle.json").toFile());) { JSONObj obj = JSONWrapper.read(in).toObject(); assertEquals("blah", obj.str("name")); }//from www. j av a 2 s . c om }
From source file:at.tfr.securefs.process.ProcessFilesBean.java
public void copy(Path fromPath, int fromStartIndex, Path toRootPath, CrypterProvider cp, BigInteger newSecret, ProcessFilesData cfd) {/*w w w . j av a 2 s . c o m*/ Path toPath = toRootPath.resolve(fromPath.subpath(fromStartIndex, fromPath.getNameCount())); try { if (Files.isRegularFile(fromPath)) { if (Files.isRegularFile(toPath)) { if (!cfd.isAllowOverwriteExisting()) { throw new SecureFSError("overwrite of existing file not allowed: " + toPath); } if (cfd.isUpdate() && Files.getLastModifiedTime(fromPath).toInstant() .isBefore(Files.getLastModifiedTime(toPath).toInstant())) { log.info("not overwriting from: " + fromPath.toAbsolutePath() + " to: " + toPath.toAbsolutePath()); return; } } // write source to target cfd.setCurrentFromPath(fromPath.toAbsolutePath().toString()); cfd.setCurrentToPath(toPath.toAbsolutePath().toString()); updateCache(cfd); try (OutputStream os = cp.getEncrypter(toPath, newSecret); InputStream is = cp.getDecrypter(fromPath)) { IOUtils.copy(is, os); } log.info("copied from: " + fromPath.toAbsolutePath() + " to: " + toPath.toAbsolutePath()); } if (Files.isDirectory(fromPath)) { Path subDir = Files.createDirectories(toPath); log.info("created subDir: " + subDir.toAbsolutePath()); } } catch (Exception e) { throw new SecureFSError("cannot copy from: " + fromPath + " to: " + toPath, e); } }
From source file:io.undertow.server.handlers.accesslog.AccessLogFileTestCase.java
@Test public void testSingleLogMessageToFile() throws IOException, InterruptedException { Path directory = logDirectory; Path logFileName = directory.resolve("server1.log"); DefaultAccessLogReceiver logReceiver = new DefaultAccessLogReceiver(DefaultServer.getWorker(), directory, "server1."); verifySingleLogMessageToFile(logFileName, logReceiver); }
From source file:io.undertow.server.handlers.accesslog.AccessLogFileTestCase.java
@Test public void testSingleLogMessageToFileWithSuffix() throws IOException, InterruptedException { Path directory = logDirectory; Path logFileName = directory.resolve("server1.logsuffix"); DefaultAccessLogReceiver logReceiver = new DefaultAccessLogReceiver(DefaultServer.getWorker(), directory, "server1.", "logsuffix"); verifySingleLogMessageToFile(logFileName, logReceiver); }