List of usage examples for java.nio.file Path toString
String toString();
From source file:io.stallion.fileSystem.FileSystemWatcherRunner.java
private void registerWatcherForFolder(IWatchEventHandler handler, String folder) { Path itemsDir = FileSystems.getDefault().getPath(folder); try {/*w w w.j a v a 2 s . co m*/ if (new File(itemsDir.toString()).isDirectory()) { itemsDir.register(watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE }, SensitivityWatchEventModifier.HIGH); Log.fine("Folder registered with watcher {0}", folder); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.spectralogic.ds3client.helpers.FileObjectGetter_Test.java
@Test public void testThatSymbolicLinksAreResolved() { Assume.assumeFalse(Platform.isWindows()); final String message = "Hello World"; final String file = "file.txt"; try {//from ww w . jav a 2 s . c o m final Path tempDirectory = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "ds3"); final Path realDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "dir")); final Path symbolicDirectory = Paths.get(tempDirectory.toString(), "symbolic"); Files.createSymbolicLink(symbolicDirectory, realDirectory); Files.createFile(Paths.get(realDirectory.toString(), file)); final ByteBuffer bb = ByteBuffer.wrap(message.getBytes()); final SeekableByteChannel getterChannel = new FileObjectGetter(symbolicDirectory).buildChannel(file); getterChannel.write(bb); getterChannel.close(); final String content = new String(Files.readAllBytes(Paths.get(realDirectory.toString(), file))); assertTrue(message.equals(content)); } catch (final IOException e) { fail("Symbolic links are not handled correctly"); } }
From source file:com.sastix.cms.server.services.content.HashedDirectoryServiceTest.java
@After public void cleanup() throws Exception { final Path path = Paths.get(VOLUME); LOGGER.info("Cleaning temp path {}", path.toString()); try {/* w w w .ja va2 s .c o m*/ deleteRecursive(path); } catch (IOException e) { //eat it } }
From source file:com.mesosphere.dcos.cassandra.common.config.Location.java
/** * Writes the Location as a Properties file. * * @param path The Path indicating where the Location will be written. * @throws IOException If the Location can not be written to path. *//*from ww w . j a va2 s.co m*/ public void writeProperties(Path path) throws IOException { logger.info("Writing properties to path: " + path.toAbsolutePath()); PrintWriter writer = new PrintWriter(path.toString(), "UTF-8"); writer.println("dc=" + dataCenter); writer.println("rack=" + rack); writer.close(); }
From source file:pinterestbackup.PINDownloader.java
private void setFileMapFound(Path pinPath) { if (!config.isSynchronized()) { return;/* w ww.j a v a2s.c o m*/ } this.localFiles.put(pinPath.toString(), Boolean.TRUE); }
From source file:io.uploader.drive.task.UploadDirectoryDriveTask.java
public UploadDirectoryDriveTask(Drive service, DriveDirectory destDir, Path srcDir, boolean overwrite, StopRequester stopRequester, HasStatusReporter statusReporter) { super(stopRequester, statusReporter); if (srcDir == null || org.apache.commons.lang3.StringUtils.isEmpty(srcDir.toString())) { throw new IllegalArgumentException("Ths source directory cannot be null"); }//from w w w . j av a 2s.c o m if (service == null) { throw new IllegalArgumentException("Ths drive cannot be null"); } if (destDir == null || org.apache.commons.lang3.StringUtils.isEmpty(destDir.getTitle())) { this.destDirTitle = null; } else { this.destDirTitle = destDir.getTitle(); } this.destDir = destDir; this.srcDir = srcDir; this.service = service; this.overwrite = overwrite; }
From source file:com.oxiane.maven.xqueryMerger.Merger.java
@Override public void execute() throws MojoExecutionException { Path sourceRootPath = inputSources.toPath(); Path destinationRootPath = outputDirectory.toPath(); IOFileFilter filter = buildFilter(); Iterator<File> it = FileUtils.iterateFiles(inputSources, filter, FileFilterUtils.directoryFileFilter()); if (!it.hasNext()) { getLog().warn("No file found matching " + filter.toString() + " in " + inputSources.getAbsolutePath()); }/*from w w w.j a v a 2s . c om*/ while (it.hasNext()) { File sourceFile = it.next(); Path fileSourcePath = sourceFile.toPath(); Path relativePath = sourceRootPath.relativize(fileSourcePath); getLog().debug("[Merger] found source: " + fileSourcePath.toString()); getLog().debug("[Merger] relative path is " + relativePath.toString()); StreamSource source = new StreamSource(sourceFile); XQueryMerger merger = new XQueryMerger(source); merger.setMainQuery(); File destinationFile = destinationRootPath.resolve(relativePath).toFile(); getLog().debug("[Merger] destination will be " + destinationFile.getAbsolutePath()); try { String result = merger.merge(); destinationFile.getParentFile().mkdirs(); OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(destinationFile), merger.getEncoding()); osw.write(result); osw.flush(); osw.close(); getLog().debug("[Merger] " + relativePath.toString() + " merged into " + destinationFile.getAbsolutePath()); } catch (ParsingException ex) { getLog().error(ex.getMessage()); throw new MojoExecutionException("Merge of " + sourceFile.getAbsolutePath() + " fails", ex); } catch (FileNotFoundException ex) { getLog().error(ex.getMessage()); throw new MojoExecutionException( "Unable to create destination " + destinationFile.getAbsolutePath(), ex); } catch (IOException ex) { getLog().error(ex.getMessage()); throw new MojoExecutionException("While writing " + destinationFile.getAbsolutePath(), ex); } } }
From source file:at.ac.tuwien.qse.sepm.service.impl.ExifServiceImpl.java
@Override public void setMetaData(Photo photo) throws ServiceException { JpegSerializer serializer = new JpegSerializer(); FileManager fileManager = new PhysicalFileManager(); logger.debug("Set metadata {}", photo); Path file = photo.getFile(); Path temp = Paths.get(file.toString() + ".temp"); InputStream is = null;/*from w ww. j a v a2 s .c o m*/ OutputStream os = null; try { if (!fileManager.exists(temp)) { try { fileManager.createFile(temp); } catch (IOException ex) { logger.warn("failed creating temp file at {}", temp); throw new ServiceException(ex); } } try { is = fileManager.newInputStream(file); } catch (IOException ex) { logger.warn("failed creating input stream for file {}", file); throw new ServiceException(ex); } try { os = fileManager.newOutputStream(temp); } catch (IOException ex) { logger.warn("failed creating output stream for file {}", temp); throw new ServiceException(ex); } try { serializer.update(is, os, photo.getData()); } catch (DAOException ex) { throw new ServiceException(ex); } } finally { try { if (is != null) { is.close(); } } catch (IOException ex) { logger.warn("failed closing input stream for file {}"); logger.error(ex); } try { if (os != null) { os.close(); } } catch (IOException ex) { logger.warn("failed closing output stream for file {}"); logger.error(ex); } } try { fileManager.copy(temp, file); } catch (IOException ex) { logger.warn("failed copying {} -> {}", temp, file); throw new ServiceException(ex); } finally { try { if (fileManager.exists(temp)) { fileManager.delete(temp); } } catch (IOException ex) { logger.warn("failed deleting temp file {}", temp); logger.error(ex); } } }
From source file:com.yevster.spdxtra.Write.java
/** * Reads inputFilePath and populates a new RDF data store at * targetDirectoryPath with its contents. * * @param inputFilePath// w ww .j av a 2 s. c o m * Must be a valid path to an RDF file. * @param newDatasetPath * The path to which to persist the RDF triple store with SPDX * data. * @return */ public static Dataset rdfIntoNewDataset(Path inputFilePath, Path newDatasetPath) { Validate.notNull(newDatasetPath); if (Files.notExists(newDatasetPath) || !Files.isDirectory(newDatasetPath)) { throw new IllegalArgumentException( "Invalid dataset path: " + newDatasetPath.toAbsolutePath().toString()); } Read.logger.debug("Creating new TDB in " + newDatasetPath.toAbsolutePath().toString()); Dataset dataset = TDBFactory.createDataset(newDatasetPath.toString()); dataset.getDefaultModel().getGraph().getPrefixMapping().setNsPrefix("spdx", SpdxUris.SPDX_TERMS); dataset.getDefaultModel().getGraph().getPrefixMapping().setNsPrefix("doap", SpdxUris.DOAP_NAMESPACE); Write.rdfIntoDataset(inputFilePath, dataset); return dataset; }
From source file:caillou.company.clonemanager.gui.service.task.impl.CloneManagerIOExceptionAdvice.java
private String getErrorMessageForIOException(Path path) { String message;/*from w ww. j av a2 s.c o m*/ if (path.toFile().exists() && path.toFile().isDirectory()) { message = ErrorMessage.VISIT_DIRECTORY_FAILED; } else { message = ErrorMessage.VISIT_FILE_FAILED; } message += path.toString(); return message; }