List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:ca.polymtl.dorsal.libdelorean.statedump.Statedump.java
/** * Retrieve a previously-saved statedump. * * @param parentPath/* w w w.ja va 2 s .c om*/ * The expected location of the statedump file. Like the * corresponding parameter in {@link #dumpState}, this is the * parent path of the TC-specific subdirectory. * @param ssid * The ID of the state system to retrieve * @return The corresponding de-serialized statedump. Returns null if there * are no statedump for this state system ID (or no statedump * directory at all). */ public static @Nullable Statedump loadState(Path parentPath, String ssid) { /* Find the state dump directory */ Path sdPath = parentPath.resolve(STATEDUMP_DIRECTORY); if (!Files.isDirectory(sdPath)) { return null; } /* Find the state dump file */ String fileName = ssid + FILE_SUFFIX; Path filePath = sdPath.resolve(fileName); if (!Files.exists(filePath)) { return null; } try (InputStreamReader in = new InputStreamReader( Files.newInputStream(filePath, StandardOpenOption.READ))) { BufferedReader bufReader = new BufferedReader(in); String json = bufReader.lines().collect(Collectors.joining("\n")); //$NON-NLS-1$ JSONObject root = new JSONObject(json); return Serialization.stateDumpFromJsonObject(root, ssid); } catch (IOException | JSONException e) { return null; } }
From source file:com.liferay.sync.engine.service.SyncAccountService.java
public static SyncAccount addSyncAccount(String filePathName, String lanCertificate, boolean lanEnabled, String lanKey, String lanServerUuid, String login, int maxConnections, String oAuthConsumerKey, String oAuthConsumerSecret, boolean oAuthEnabled, String oAuthToken, String oAuthTokenSecret, String password, String pluginVersion, int pollInterval, Map<SyncSite, List<SyncFile>> ignoredSyncFiles, SyncUser syncUser, boolean trustSelfSigned, String url) throws Exception { // Sync account SyncAccount syncAccount = new SyncAccount(); syncAccount.setFilePathName(filePathName); syncAccount.setLanCertificate(lanCertificate); syncAccount.setLanEnabled(lanEnabled); syncAccount.setLanKey(lanKey);/*from ww w. j a v a 2s. com*/ syncAccount.setLanServerUuid(lanServerUuid); syncAccount.setLogin(login); syncAccount.setMaxConnections(maxConnections); syncAccount.setPluginVersion(pluginVersion); syncAccount.setOAuthConsumerKey(oAuthConsumerKey); syncAccount.setOAuthConsumerSecret(oAuthConsumerSecret); syncAccount.setOAuthEnabled(oAuthEnabled); syncAccount.setOAuthToken(oAuthToken); syncAccount.setOAuthTokenSecret(SyncEncryptor.encrypt(oAuthTokenSecret)); syncAccount.setPassword(SyncEncryptor.encrypt(password)); syncAccount.setPollInterval(pollInterval); syncAccount.setTrustSelfSigned(trustSelfSigned); syncAccount.setUrl(url); _syncAccountPersistence.create(syncAccount); // Sync file Path filePath = Paths.get(filePathName); Path dataFilePath = Files.createDirectories(filePath.resolve(".data")); if (OSDetector.isWindows()) { Files.setAttribute(dataFilePath, "dos:hidden", true); } SyncFileService.addSyncFile(null, null, false, null, filePathName, null, String.valueOf(filePath.getFileName()), 0, 0, 0, SyncFile.STATE_SYNCED, syncAccount.getSyncAccountId(), SyncFile.TYPE_SYSTEM); // Sync sites for (Map.Entry<SyncSite, List<SyncFile>> entry : ignoredSyncFiles.entrySet()) { // Sync site SyncSite syncSite = entry.getKey(); String siteFilePathName = FileUtil.getFilePathName(syncAccount.getFilePathName(), syncSite.getSanitizedName()); while (true) { SyncSite existingSyncSite = SyncSiteService.fetchSyncSite(siteFilePathName, syncAccount.getSyncAccountId()); if (existingSyncSite == null) { break; } siteFilePathName = FileUtil.getNextFilePathName(siteFilePathName); } syncSite.setFilePathName(siteFilePathName); syncSite.setRemoteSyncTime(-1); syncSite.setSyncAccountId(syncAccount.getSyncAccountId()); SyncSiteService.update(syncSite); // Sync file SyncFileService.addSyncFile(null, null, false, null, syncSite.getFilePathName(), null, syncSite.getName(), 0, syncSite.getGroupId(), 0, SyncFile.STATE_SYNCED, syncSite.getSyncAccountId(), SyncFile.TYPE_SYSTEM); if (syncSite.isActive() && !FileUtil.exists(Paths.get(syncSite.getFilePathName()))) { Files.createDirectories(Paths.get(syncSite.getFilePathName())); } // Sync files for (SyncFile childSyncFile : entry.getValue()) { childSyncFile.setModifiedTime(0); childSyncFile.setState(SyncFile.STATE_UNSYNCED); childSyncFile.setSyncAccountId(syncSite.getSyncAccountId()); SyncFileService.update(childSyncFile); } } // Sync user if (syncUser != null) { syncUser.setSyncAccountId(syncAccount.getSyncAccountId()); SyncUserService.update(syncUser); } return syncAccount; }
From source file:eu.itesla_project.eurostag.EurostagImpactAnalysis.java
private static void dumpLinesDictionary(Network network, EurostagDictionary dictionary, Path dir) throws IOException { try (BufferedWriter os = Files.newBufferedWriter(dir.resolve("dict_lines.csv"), StandardCharsets.UTF_8)) { for (Identifiable obj : Identifiables.sort(Iterables.concat(network.getLines(), network.getTwoWindingsTransformers(), network.getDanglingLines()))) { os.write(obj.getId() + ";" + dictionary.getEsgId(obj.getId())); os.newLine();//from w w w. j a v a2s .co m } for (ThreeWindingsTransformer twt : Identifiables.sort(network.getThreeWindingsTransformers())) { throw new AssertionError("TODO"); } } }
From source file:com.facebook.buck.util.unarchive.Unzip.java
/** * Get a listing of all files in a zip file * * @param zip The zip file to scan/* www .j av a2 s.c o m*/ * @param relativePath The relative path where the extraction will be rooted * @return The list of paths in {@code zip} sorted by path so dirs come before contents. */ private static SortedMap<Path, ZipArchiveEntry> getZipFilePaths(ZipFile zip, Path relativePath, PatternsMatcher entriesToExclude) { SortedMap<Path, ZipArchiveEntry> pathMap = new TreeMap<>(); for (ZipArchiveEntry entry : Collections.list(zip.getEntries())) { String entryName = entry.getName(); if (entriesToExclude.matchesAny(entryName)) { continue; } Path target = relativePath.resolve(entryName).normalize(); pathMap.put(target, entry); } return pathMap; }
From source file:fr.inria.atlanmod.neoemf.benchmarks.datastore.helper.BackendHelper.java
private static File createStore(File sourceFile, InternalBackend targetBackend, Path targetDir) throws Exception { checkValidResource(sourceFile.getName()); checkArgument(sourceFile.exists(), "Resource '%s' does not exist", sourceFile); String targetFileName = Files.getNameWithoutExtension(sourceFile.getAbsolutePath()) + "." + targetBackend.getStoreExtension(); File targetFile = targetDir.resolve(targetFileName).toFile(); if (targetFile.exists()) { log.info("Already existing store {}", targetFile); return targetFile; }//w w w . j ava2 s . c o m ResourceSet resourceSet = loadResourceSet(); URI sourceUri = URI.createFileURI(sourceFile.getAbsolutePath()); Resource sourceResource = resourceSet.createResource(sourceUri); Resource targetResource = targetBackend.createResource(targetFile, resourceSet); targetBackend.initAndGetEPackage(); log.info("Loading '{}'", sourceUri); Map<String, Object> loadOpts = new HashMap<>(); if (Objects.equals(ZXMI, sourceUri.fileExtension())) { loadOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); } sourceResource.load(loadOpts); log.info("Migrating"); targetBackend.save(targetResource); targetResource.getContents().addAll(sourceResource.getContents()); sourceResource.unload(); log.info("Saving to '{}'", targetResource.getURI()); targetBackend.save(targetResource); targetBackend.unload(targetResource); return targetFile; }
From source file:au.org.ands.vocabs.toolkit.utils.ToolkitFileUtils.java
/** Get the full path of the directory used to store all * the files referred to by the task.//from www .j a v a2s. c o m * @param taskInfo The TaskInfo object representing the task. * @param extraPath An optional additional path component to be added * at the end. If not required, pass in null or an empty string. * @return The full path of the directory used to store the * vocabulary data. */ public static String getTaskOutputPath(final TaskInfo taskInfo, final String extraPath) { // NB: We call makeSlug() on the vocabulary slug, which should // (as of ANDS-Registry-Core commit e365392831ae) // not really be necessary. Path path = Paths.get(ToolkitConfig.DATA_FILES_PATH).resolve(makeSlug(taskInfo.getVocabulary().getOwner())) .resolve(makeSlug(taskInfo.getVocabulary().getSlug())) .resolve(makeSlug(taskInfo.getVersion().getTitle())); if (extraPath != null && (!extraPath.isEmpty())) { path = path.resolve(extraPath); } return path.toString(); }
From source file:com.github.anba.es6draft.util.Resources.java
/** * Returns the resource path if available. */// www. j a v a 2 s . c o m public static Path resourcePath(String uri, Path basedir) { final String RESOURCE = "resource:"; if (uri.startsWith(RESOURCE)) { return null; } else { return basedir.resolve(Paths.get(uri)).toAbsolutePath(); } }
From source file:com.bc.fiduceo.post.PostProcessingTool.java
static PostProcessingContext initializeContext(CommandLine commandLine) throws IOException { logger.info("Loading configuration ..."); final PostProcessingContext context = new PostProcessingContext(); final String configValue = commandLine.getOptionValue("config", "./config"); final Path configDirectory = Paths.get(configValue); final SystemConfig systemConfig = SystemConfig.loadFrom(configDirectory.toFile()); context.setSystemConfig(systemConfig); final String jobConfigPathString = commandLine.getOptionValue("job-config"); final Path jobConfigPath = Paths.get(jobConfigPathString); final InputStream inputStream = Files.newInputStream(configDirectory.resolve(jobConfigPath)); final PostProcessingConfig jobConfig = PostProcessingConfig.load(inputStream); context.setProcessingConfig(jobConfig); final String startDate = getDate(commandLine, "start"); context.setStartDate(TimeUtils.parseDOYBeginOfDay(startDate)); final String endDate = getDate(commandLine, "end"); context.setEndDate(TimeUtils.parseDOYEndOfDay(endDate)); final String mmdFilesDir = commandLine.getOptionValue("input-dir"); context.setMmdInputDirectory(Paths.get(mmdFilesDir)); logger.info("Success loading configuration."); return context; }
From source file:com.sonar.it.scanner.msbuild.TestUtils.java
public static Path prepareCSharpPlugin(TemporaryFolder temp) { Path t; try {/*from w w w . j a v a2 s .com*/ t = temp.newFolder("CSharpPlugin").toPath(); } catch (IOException e) { throw new IllegalStateException(e); } Configuration configuration = Orchestrator.builderEnv().build().getConfiguration(); Locators locators = new Locators(configuration); String pluginVersion = TestSuite.getCSharpVersion(); MavenLocation csharp = MavenLocation.create("org.sonarsource.dotnet", "sonar-csharp-plugin", pluginVersion); Path modifiedCs = t.resolve("modified-chsarp.jar"); if (locators.copyToFile(csharp, modifiedCs.toFile()) == null) { throw new IllegalStateException( "Couldn't locate csharp plugin in the local maven repository: " + csharp); } String scannerPayloadVersion = getScannerPayloadVersion(); Path scannerImpl; if (scannerPayloadVersion != null) { LOG.info("Updating C# plugin ({}) with Scanner For MSBuild implementation ({})", pluginVersion, scannerPayloadVersion); MavenLocation scannerImplLocation = MavenLocation.builder() .setGroupId("org.sonarsource.scanner.msbuild").setArtifactId("sonar-scanner-msbuild") .setVersion(scannerPayloadVersion).setClassifier("impl").withPackaging("zip").build(); scannerImpl = t.resolve("sonar-scanner-msbuild-impl.zip"); if (locators.copyToFile(scannerImplLocation, scannerImpl.toFile()) == null) { throw new IllegalStateException("Unable to find sonar-scanner-msbuild " + scannerPayloadVersion + " in local Maven repository"); } } else { // Run locally LOG.info("Updating C# plugin ({}) with local build of Scanner For MSBuild implementation", pluginVersion); scannerImpl = Paths.get( "../DeploymentArtifacts/CSharpPluginPayload/Release/SonarQube.MSBuild.Runner.Implementation.zip"); } replaceInZip(modifiedCs.toUri(), scannerImpl, "/static/SonarQube.MSBuild.Runner.Implementation.zip"); return modifiedCs; }
From source file:org.apache.taverna.databundle.DataBundles.java
public static Path getWorkflowDescription(Bundle dataBundle) throws IOException { Path annotations = getAnnotations(dataBundle); return annotations.resolve(WORKFLOW + DOT_WFDESC_TTL); }