List of usage examples for java.nio.file Path toString
String toString();
From source file:com.compomics.colims.distributed.playground.AnnotatedSpectraParser.java
/** * Parse the APL files for given aplKeys and put the peaks in the spectrumPeaks list. *///from ww w. j a va2 s . c o m private void parseAplFile() throws IOException { for (Path aplFilePath : aplFilePaths.keySet()) { if (!Files.exists(aplFilePath)) { throw new FileNotFoundException( "The apl spectrum file " + aplFilePath.toString() + " could not be found."); } try (BufferedReader bufferedReader = Files.newBufferedReader(aplFilePath)) { String line; Map<String, String> headers = new HashMap<>(); while ((line = bufferedReader.readLine()) != null) { //look for a spectrum entry if (line.startsWith(APL_SPECTUM_START)) { //go to the next line line = bufferedReader.readLine(); //parse spectrum header part while (!Character.isDigit(line.charAt(0))) { String[] split = line.split(APL_HEADER_DELIMITER); headers.put(split[0], split[1]); line = bufferedReader.readLine(); } //" Precursor: 0 _multi_" is removed before looking up the key in the spectra map String header = org.apache.commons.lang3.StringUtils .substringBefore(headers.get(APL_HEADER), " Precursor"); //check if the spectrum was identified and therefore can be found in the spectra map if (aplKeys.contains(header)) { List<Peak> peakList = new ArrayList<>(); while (!line.startsWith(APL_SPECTUM_END)) { String[] splitLine = line.split(MaxQuantConstants.PARAM_TAB_DELIMITER.value()); Peak peak = new Peak(Double.parseDouble(splitLine[0]), Double.parseDouble(splitLine[1])); peakList.add(peak); line = bufferedReader.readLine(); } spectrumPeaks.put(header, peakList); } //clear headers map headers.clear(); } } } } }
From source file:com.romeikat.datamessie.core.base.util.FileUtil.java
public synchronized Path createXlsxFile(final Path dir, final String filename, final SXSSFWorkbook xlsxWorkbook) { return Paths.get(createXlsxFile(dir.toString(), filename, xlsxWorkbook).getAbsolutePath()); }
From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java
@Test public void testThatFileReportsAsRegularOnWindows() throws IOException, InterruptedException { Assume.assumeTrue(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String A_FILE_NAME = "aFile.txt"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {/*from ww w.j a va 2s .co m*/ Files.createFile(Paths.get(tempDirectory.toString(), A_FILE_NAME)); new FileObjectPutter(tempDirectory).buildChannel(A_FILE_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(A_FILE_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertFalse(caughtException.get()); }
From source file:functionaltests.job.workingdir.TestForkedTaskWorkingDir.java
private void javaTaskTaskRestartedAnotherNode() throws Exception { FileLock blockTaskFromTest = new FileLock(); Path blockTaskFromTestPath = blockTaskFromTest.lock(); FileLock blockTestBeforeKillingNode = new FileLock(); Path blockTestBeforeKillingNodePath = blockTestBeforeKillingNode.lock(); TaskFlowJob job = createFileInLocalSpaceJob(blockTaskFromTestPath.toString(), blockTestBeforeKillingNodePath.toString()); JobId idJ1 = schedulerHelper.submitJob(job); SchedulerTHelper.log("Wait until task is in the middle of the run"); final String taskNodeUrl = findNodeRunningTask(); schedulerHelper.waitForEventTaskRunning(idJ1, "task1"); FileLock.waitUntilUnlocked(blockTestBeforeKillingNodePath); SchedulerTHelper.log("Kill the node running the task"); schedulerHelper.killNode(taskNodeUrl); SchedulerTHelper.log("Let the task finish"); blockTaskFromTest.unlock();/*w w w .jav a 2 s . com*/ SchedulerTHelper.log("Waiting for job 1 to finish"); schedulerHelper.waitForEventJobFinished(idJ1); String userSpaceUri = URI.create(schedulerHelper.getSchedulerInterface().getUserSpaceURIs().get(0)) .getPath(); assertTrue("Could not find expected output file", new File(userSpaceUri, "output_file.txt").exists()); }
From source file:fr.ortolang.diffusion.client.cmd.CheckBagCommand.java
private void checkSnapshotMetadata(Path root) { Path metadata = Paths.get(root.toString(), "metadata"); try {// ww w. j ava 2 s .c om Files.walkFileTree(metadata, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path target = Paths.get(root.toString(), "objects", metadata.relativize(file.getParent()).toString()); if (!Files.exists(target)) { errors.append("-> unexisting target for metadata: ").append(file).append("\r\n"); if (fix) { try { Files.delete(file); fixed.append("-> deleted metadata: ").append(file).append("\r\n"); } catch (IOException e) { errors.append("-> unable to fix: ").append(e.getMessage()).append("\r\n"); } } } else if (file.endsWith("ortolang-item-json")) { checkOrtolangItemJson(file); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (IOException e) { System.out.println("Unable to walk file tree: " + e.getMessage()); } }
From source file:it.greenvulcano.configuration.BaseConfigurationManager.java
@Override public void delete(String name) throws IOException, FileNotFoundException { Path configurationPath = getConfigurationPath(name); if (!Files.deleteIfExists(configurationPath)) { throw new FileNotFoundException(configurationPath.toString()); }/* w w w . ja v a2s.c om*/ }
From source file:eu.forgetit.middleware.component.Contextualizer.java
private List<File> getFilteredDocumentList(Path contentPath) { List<File> filteredDocuments = new ArrayList<>(); File contentDir = new File(contentPath.toString()); String[] contentFiles = contentDir.list(); if (contentFiles == null || contentFiles.length == 0) return filteredDocuments; List<String> formatList = Arrays.asList( ConfigurationManager.getConfiguration().getStringArray("contextualizer.context.analysis.formats")); logger.debug("Accepted document formats:" + formatList); String format = null;/*from w ww . j av a 2s . co m*/ Tika tika = new Tika(); for (String file : contentFiles) { format = tika.detect(file); logger.debug("Found file in content dir: " + file + " (" + format + ")"); if (formatList.contains(format)) { filteredDocuments.add(new File(contentDir, file)); logger.debug("New document added to list: " + contentDir + "/" + file); } } return filteredDocuments; }
From source file:com.bekwam.resignator.commands.UnsignCommand.java
private void repackJAR(Path targetJARFilePath, Path appDir) throws CommandExecutionException { Preconditions.checkNotNull(activeConfiguration.getJarCommand()); String[] cmdAndArgs = { activeConfiguration.getJarCommand().toString(), "cMf", targetJARFilePath.toString(), "-C", tempDir.toAbsolutePath().toString(), "." }; CommandExecutor cmd = new CommandExecutor(); cmd.exec(cmdAndArgs);//from w w w . ja v a 2s. c o m }
From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java
@Test public void testThatNamedPipeThrows() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String FIFO_NAME = "bFifo"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {/* w w w.j a v a 2s . co m*/ Runtime.getRuntime().exec("mkfifo " + Paths.get(tempDirectory.toString(), FIFO_NAME)).waitFor(); new FileObjectPutter(tempDirectory).buildChannel(FIFO_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(FIFO_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertTrue(caughtException.get()); }
From source file:io.uploader.drive.drive.DriveOperations.java
private static Map<Path, File> createDirectoriesStructure(OperationResult operationResult, Drive client, File driveDestDirectory, Path srcDir, final StopRequester stopRequester, final HasStatusReporter statusReporter) throws IOException { Queue<Path> directoriesQueue = io.uploader.drive.util.FileUtils.getAllFilesPath(srcDir, FileFinderOption.DIRECTORY_ONLY); if (statusReporter != null) { statusReporter.setCurrentProgress(0.0); statusReporter.setTotalProgress(0.0); statusReporter.setStatus("Checking/creating directories structure..."); }//from w w w .ja v a 2 s . c o m long count = 0; Path topParent = srcDir.getParent(); Map<Path, File> localPathDriveFileMapping = new HashMap<Path, File>(); localPathDriveFileMapping.put(topParent, driveDestDirectory); for (Path path : directoriesQueue) { try { if (statusReporter != null) { statusReporter.setCurrentProgress(0.0); statusReporter.setStatus( "Checking/creating directories structure... (" + path.getFileName().toString() + ")"); } if (hasStopBeenRequested(stopRequester)) { if (statusReporter != null) { statusReporter.setStatus("Stopped!"); } operationResult.setStatus(OperationCompletionStatus.STOPPED); return localPathDriveFileMapping; } File driveParent = localPathDriveFileMapping.get(path.getParent()); if (driveParent == null) { throw new IllegalStateException( "The path " + path.toString() + " does not have any parent in the drive (parent path " + path.getParent().toString() + ")..."); } // check whether driveParent already exists, otherwise create it File driveDirectory = createDirectoryIfNotExist(client, driveParent, path.getFileName().toString()); localPathDriveFileMapping.put(path, driveDirectory); ++count; if (statusReporter != null) { double p = ((double) count) / directoriesQueue.size(); statusReporter.setTotalProgress(p); statusReporter.setCurrentProgress(1.0); } } catch (Throwable e) { logger.error("Error occurred while creating the directory " + path.toString(), e); operationResult.setStatus(OperationCompletionStatus.ERROR); operationResult.addError(path, e); } } return localPathDriveFileMapping; }