List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:com.nridge.connector.fs.con_fs.core.FileCrawler.java
/** * Invoked for a file in a directory.// ww w . ja v a2 s . c om * Unless overridden, this method returns {@link java.nio.file.FileVisitResult#CONTINUE * CONTINUE}. * * @param aPath Path instance. * @param aFileAttributes File attribute instance. */ @Override public FileVisitResult visitFile(Path aPath, BasicFileAttributes aFileAttributes) throws IOException { Logger appLogger = mAppMgr.getLogger(this, "visitFile"); String pathFileName = aPath.toAbsolutePath().toString(); if (mCrawlIgnore.isMatchedNormalized(pathFileName)) appLogger.debug(String.format("Ignoring File: %s", pathFileName)); else { File fsFile = aPath.toFile(); if ((fsFile.canRead()) && (mBag != null)) { String crawlType = mCrawlQueue.getCrawlType(); if (StringUtils.equals(crawlType, Connector.CRAWL_TYPE_INCREMENTAL)) { String docId = generateDocumentId(aPath); boolean docExistsInIndex = documentExistsInIndex(docId); if (docExistsInIndex) { Date incDate = mCrawlQueue.getCrawlLastModified(); FileTime lastModifiedTime = aFileAttributes.lastModifiedTime(); Date lmDate = new Date(lastModifiedTime.toMillis()); if (lmDate.after(incDate)) processFile(aPath, aFileAttributes); } else processFile(aPath, aFileAttributes); } else processFile(aPath, aFileAttributes); } else appLogger.warn(String.format("Access Failed: %s", pathFileName)); } if (mAppMgr.isAlive()) return FileVisitResult.CONTINUE; else return FileVisitResult.TERMINATE; }
From source file:org.apache.tika.batch.fs.FSOutputStreamFactory.java
/** * This tries to create a file based on the {@link org.apache.tika.batch.fs.FSUtil.HANDLE_EXISTING} * value that was passed in during initialization. * <p>/*from w w w . j a v a2 s. c o m*/ * If {@link #handleExisting} is set to "SKIP" and the output file already exists, * this will return null. * <p> * If an output file can be found, this will try to mkdirs for that output file. * If mkdirs() fails, this will throw an IOException. * <p> * Finally, this will open an output stream for the appropriate output file. * @param metadata must have a value set for FSMetadataProperties.FS_ABSOLUTE_PATH or * else NullPointerException will be thrown! * @return OutputStream * @throws java.io.IOException, NullPointerException */ @Override public OutputStream getOutputStream(Metadata metadata) throws IOException { String initialRelativePath = metadata.get(FSProperties.FS_REL_PATH); Path outputPath = FSUtil.getOutputPath(outputRoot, initialRelativePath, handleExisting, suffix); if (outputPath == null) { return null; } if (!Files.isDirectory(outputPath.getParent())) { Files.createDirectories(outputPath.getParent()); //TODO: shouldn't need this any more in java 7, right? if (!Files.isDirectory(outputPath.getParent())) { throw new IOException("Couldn't create parent directory for:" + outputPath.toAbsolutePath()); } } OutputStream os = Files.newOutputStream(outputPath); switch (compression) { case BZIP2: os = new BZip2CompressorOutputStream(os); break; case GZIP: os = new GZIPOutputStream(os); break; case ZIP: os = new ZipArchiveOutputStream(os); break; } return new BufferedOutputStream(os); }
From source file:com.bc.fiduceo.post.PostProcessingTool.java
private void computeFile(Path mmdFile, final SourceTargetManager manager, List<PostProcessing> processings) throws IOException, InvalidRangeException { final long startTime = context.getStartDate().getTime(); final long endTime = context.getEndDate().getTime(); if (isFileInTimeRange(startTime, endTime, mmdFile.getFileName().toString())) { logger.info("Compute file '" + mmdFile.getFileName().toString() + "'"); final Path source = manager.getSource(mmdFile); final Path target = manager.getTargetPath(mmdFile); NetcdfFile reader = null;/*from w ww . j ava 2s . c o m*/ NetcdfFileWriter writer = null; try { final String absSource = source.toAbsolutePath().toString(); // open the file that way is needed because the standard open mechanism changes the file size reader = NetCDFUtils.openReadOnly(absSource); final String absTarget = target.toAbsolutePath().toString(); if (DataFormatType.NETCDF.name().equalsIgnoreCase(reader.getFileTypeId())) { writer = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, absTarget); } else { final Nc4Chunking chunking = Nc4ChunkingDefault.factory(Nc4Chunking.Strategy.standard, 5, true); writer = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf4, absTarget, chunking); } run(reader, writer, processings); } finally { if (reader != null) { reader.close(); } if (writer != null) { // when writer is in define mode, the file has not been created. Closing it in this state causes a // null pointer exception tb 2016-12-21 if (!writer.isDefineMode()) { writer.close(); } } } } }
From source file:org.ng200.openolympus.cerberus.compilers.JavaCompiler.java
@Override public void compile(final List<Path> inputFiles, final Path outputFile, final Map<String, Object> additionalParameters) throws CompilationException, IOException { FileAccess.createDirectories(outputFile); final CommandLine commandLine = new CommandLine("javac"); commandLine.setSubstitutionMap(additionalParameters); this.arguments.forEach((arg) -> commandLine.addArgument(arg)); commandLine.addArgument("-d"); commandLine.addArgument(outputFile.toAbsolutePath().toString()); commandLine.addArgument("-nowarn"); // Prohibit warnings because they // screw//from w w w.j a v a2s . c o m // up error detection inputFiles.forEach((file) -> commandLine .addArguments(MessageFormat.format("\"{0}\"", file.toAbsolutePath().toString()))); // Add // input // files JavaCompiler.logger.info("Running javac with arguments: {}", Arrays.asList(commandLine.getArguments())); final DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 0, 1 }); final ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(null, errorStream, null)); executor.setWatchdog(new ExecuteWatchdog(20000));// 20 seconds to // compile int result; try { result = executor.execute(commandLine); } catch (final IOException e) { JavaCompiler.logger.error("Could not execute javac: {}", e); throw new CompilationException("Could not execute javac", e); } switch (result) { case 0: return; case 1: try { String errorString = errorStream.toString("UTF-8"); final Pattern pattern = Pattern.compile( "^(" + inputFiles.stream().map(file -> Pattern.quote(file.toAbsolutePath().toString())) .collect(Collectors.joining("|")) + "):", Pattern.MULTILINE); errorString = pattern.matcher(errorString).replaceAll(""); JavaCompiler.logger.debug("Compilation error: {}", errorString); throw new CompilerError("javac.wrote.stderr", errorString); } catch (final UnsupportedEncodingException e) { throw new CompilationException("Unsupported encoding! The compiler should output UTF-8!", e); } } }
From source file:org.ballerinalang.composer.service.fs.LocalFileSystem.java
private JsonObject getJsonObjForFile(Path root, List<String> extensions) { JsonObject rootObj = new JsonObject(); Path fileName = root.getFileName(); if (fileName != null) { rootObj.addProperty(NODE_LABEL, fileName.toString()); } else {/*from w ww.j a va 2 s. c om*/ rootObj.addProperty(NODE_LABEL, root.toString()); } rootObj.addProperty(NODE_ID, root.toAbsolutePath().toString()); Path parent = root.getParent(); if (parent != null) { rootObj.addProperty(PARENT, parent.toAbsolutePath().toString()); } if (Files.isDirectory(root)) { rootObj.addProperty(NODE_TYPE, FOLDER_TYPE); try { File rootFile = root.toFile(); boolean hasChildren = Boolean.FALSE; if (rootFile != null) { // check if this folder contains sub-directories File[] subDirs = rootFile.listFiles(File::isDirectory); if (subDirs != null && subDirs.length > 0) { hasChildren = Boolean.TRUE; } else { // if there are no sub-directories, check whether this folder // contains files with given extension list String[] list = extensions != null && !extensions.isEmpty() ? rootFile.list(new SuffixFileFilter(extensions, INSENSITIVE)) : rootFile.list(); if (list != null && list.length > 0) { hasChildren = true; } } } rootObj.addProperty(NODE_CHILDREN, hasChildren); } catch (Exception e) { logger.debug("Error while fetching children of " + root.toString(), e); rootObj.addProperty(NODE_ERROR, e.toString()); } } else if (Files.isRegularFile(root)) { rootObj.addProperty(NODE_TYPE, FILE_TYPE); rootObj.addProperty(NODE_CHILDREN, Boolean.FALSE); } return rootObj; }
From source file:edu.pitt.dbmi.ccd.queue.service.AlgorithmSlurmService.java
public Future<Void> submitJobtoSlurm(JobQueueInfo jobQueueInfo) { Long queueId = jobQueueInfo.getId(); String fileName = jobQueueInfo.getFileName() + ".txt"; String commands = jobQueueInfo.getCommands(); String tmpDirectory = jobQueueInfo.getTmpDirectory(); Properties p = new Properties(); // Upload dataset(s) to the remote data storage Set<UserAccount> userAccounts = jobQueueInfo.getUserAccounts(); UserAccount userAccount = (UserAccount) userAccounts.toArray()[0]; String username = userAccount.getUsername(); Path checkUserDirTemplate = Paths.get(workspace, jobTemplates, checkUserDir); String checkUserDirTemplateDir = checkUserDirTemplate.toAbsolutePath().toString(); p.setProperty("causalUser", username); p.setProperty("tmp", tempFolder); p.setProperty("results", resultFolder); p.setProperty("algorithm", algorithmResultFolder); String partition = hpcPartition; int walltime = hpcWallTime; Set<HpcParameter> hpcParameters = jobQueueInfo.getHpcParameters(); if (hpcParameters != null && !hpcParameters.isEmpty()) { for (HpcParameter param : hpcParameters) { if (param.getParameterKey().equalsIgnoreCase("partition")) { partition = param.getParameterValue(); }/* w w w . j ava 2 s. c o m*/ String key = param.getParameterKey(); String value = param.getParameterValue(); switch (key) { case "partition": partition = value; break; case "walltime": walltime = Integer.parseInt(value); break; } } } p.setProperty("partition", partition); p.setProperty("walltime", String.format("%02d:00:00", walltime)); List<String> cmdList = new LinkedList<>(); cmdList.addAll(Arrays.asList(commands.split(";"))); String datasets = null; for (int i = 0; i < cmdList.size(); i++) { String cmd = cmdList.get(i); if (cmd.equalsIgnoreCase("--data")) { datasets = cmdList.get(i + 1); break; } } List<String> datasetList = new LinkedList<>(); datasetList.addAll(Arrays.asList(datasets.split(","))); // The current dataset path is the one on the grid datasetList.forEach(dataset -> { // Extract fileName from the dataset Path dataPath = Paths.get(remotedataspace, username, dataFolder); String dataFile = dataset.replace(dataPath.toAbsolutePath().toString(), ""); //The dataset's source path dataPath = Paths.get(workspace, username, dataFolder, dataFile); Path scriptPath = Paths.get(remoteworkspace, checkUserDirScript); String scriptDir = scriptPath.toAbsolutePath().toString() + username + ".sh"; LOGGER.info("submitJobtoSlurm: checkUserDirScript: " + scriptDir); try { client.uploadFile(checkUserDirTemplateDir, p, scriptDir, dataPath.toAbsolutePath().toString(), dataset); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }); String knowledges = null; for (int i = 0; i < cmdList.size(); i++) { String cmd = cmdList.get(i); if (cmd.equalsIgnoreCase("--knowledge")) { knowledges = cmdList.get(i + 1); break; } } if (knowledges != null) { List<String> knowledgeList = new LinkedList<>(); knowledgeList.addAll(Arrays.asList(knowledges.split(","))); knowledgeList.forEach(knowledge -> { // Extract fileName from the knowledge path Path knowledgePath = Paths.get(remotedataspace, username, dataFolder); String knowledgeFile = knowledge.replace(knowledgePath.toAbsolutePath().toString(), ""); //The knowledge's source path knowledgePath = Paths.get(workspace, username, dataFolder, knowledgeFile); Path scriptPath = Paths.get(remoteworkspace, checkUserDirScript); String scriptDir = scriptPath.toAbsolutePath().toString() + username + ".sh"; LOGGER.info("submitJobtoSlurm: checkUserDirScript: " + scriptDir); try { client.uploadFile(checkUserDirTemplateDir, p, scriptDir, knowledgePath.toAbsolutePath().toString(), knowledge); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }); } cmdList.add("--out"); cmdList.add(tmpDirectory); String errorFileName = String.format("error_%s", fileName); Path error = Paths.get(tmpDirectory, errorFileName); // Redirect Error to File cmdList.add("2>"); cmdList.add(error.toAbsolutePath().toString()); StringBuilder sb = new StringBuilder(); cmdList.forEach(cmd -> { sb.append(cmd); sb.append(" "); }); LOGGER.info("Algorithm command: " + sb.toString()); try { // Submit a job & Get remote job Id p.setProperty("email", userAccount.getPerson().getEmail()); p.setProperty("cmd", sb.toString()); Path causalJobTemplate = Paths.get(workspace, jobTemplates, causalJob); String causalJobTemplateDir = causalJobTemplate.toAbsolutePath().toString(); Path scriptPath = Paths.get(remoteworkspace, username, runSlurmJobScript); String scriptDir = scriptPath.toAbsolutePath().toString() + queueId + ".sh"; LOGGER.info("submitJobtoSlurm: runSlurmJobScript: " + scriptDir); long pid = client.submitJob(causalJobTemplateDir, p, scriptDir); JobQueueInfo queuedJobInfo = jobQueueInfoService.findOne(queueId); LOGGER.info("Set Job's pid to be: " + pid); queuedJobInfo.setPid(pid); jobQueueInfoService.saveJobIntoQueue(queuedJobInfo); } catch (Exception exception) { LOGGER.error("Algorithm did not run successfully.", exception); } return new AsyncResult<>(null); }
From source file:org.wso2.appserver.integration.tests.webapp.virtualhost.VirtualHostWebApplicationDeploymentTestCase.java
@BeforeClass(alwaysRun = true) public void init() throws Exception { super.init(); serverManager = new ServerConfigurationManager(asServer); //restart server with virtual hosts Path sourcePath = Paths.get(TestConfigurationProvider.getResourceLocation(), "artifacts", "AS", "tomcat", "catalina-server.xml"); Path targetPath = Paths.get(System.getProperty(ServerConstants.CARBON_HOME), "repository", "conf", "tomcat", "catalina-server.xml"); File sourceFile = new File(sourcePath.toAbsolutePath().toString()); File targetFile = new File(targetPath.toAbsolutePath().toString()); serverManager.applyConfigurationWithoutRestart(sourceFile, targetFile, true); serverManager.restartForcefully();/*ww w . j a va2 s .co m*/ super.init(); webAppAdminClient = new WebAppAdminClient(backendURL, sessionCookie); }
From source file:com.facebook.buck.util.ProjectFilesystemTest.java
@Test public void testCreateContextStringForModifyEvent() throws IOException { Path file = tmp.newFile("foo.txt").toPath(); WatchEvent<Path> modifyEvent = WatchEvents.createPathEvent(file, StandardWatchEventKinds.ENTRY_MODIFY); assertEquals(file.toAbsolutePath().toString(), filesystem.createContextString(modifyEvent)); }
From source file:org.sonarsource.scanner.cli.ConfTest.java
@Test public void shouldLoadCompleteConfiguration() throws Exception { Path runnerHome = Paths .get(getClass().getResource("ConfTest/shouldLoadCompleteConfiguration/runner").toURI()); Path projectHome = Paths .get(getClass().getResource("ConfTest/shouldLoadCompleteConfiguration/project").toURI()); args.setProperty("scanner.home", runnerHome.toAbsolutePath().toString()); args.setProperty("project.home", projectHome.toAbsolutePath().toString()); Properties properties = conf.properties(); assertThat(properties.getProperty("project.prop")).isEqualTo("foo"); assertThat(properties.getProperty("overridden.prop")).isEqualTo("project scope"); assertThat(properties.getProperty("global.prop")).isEqualTo("jdbc:mysql:localhost/sonar"); assertThat(properties.getProperty("sonar.projectBaseDir")).isEqualTo(projectHome.toString()); }
From source file:org.sonar.plugins.csharp.CSharpSensor.java
void executeInternal(SensorContext context) { boolean requiresAnalyzerScannerExecution = !config.isReportsComingFromMSBuild(); LOG.info("SonarAnalyzer.Scanner needs to be executed: " + requiresAnalyzerScannerExecution); String roslynReportPath = settings.getString(config.getRoslynJsonReportPathProperty()); boolean hasRoslynReportPath = roslynReportPath != null; Path protobufReportsDirectory; if (requiresAnalyzerScannerExecution) { // MSBuild 12 or MSBuild 14 with old scanner analyze(!hasRoslynReportPath, context); protobufReportsDirectory = protobufReportPathForMSBuild12(context); } else {/*w ww . j ava 2 s. c o m*/ protobufReportsDirectory = config.protobufReportPathFromScanner(); } LOG.info("Importing analysis results from " + protobufReportsDirectory.toAbsolutePath().toString()); importResults(context, protobufReportsDirectory, !hasRoslynReportPath); if (hasRoslynReportPath) { LOG.info("Importing Roslyn report"); importRoslynReport(roslynReportPath, context); } }