List of usage examples for java.nio.file Path toString
String toString();
From source file:org.eclipse.vorto.remoterepository.internal.dao.FilesystemModelDAO.java
@Override public Collection<ModelContent> getAllModels(ModelType modelType) { final Collection<ModelContent> allModels = new ArrayList<ModelContent>(); final String fileExtension = getModelExtension(modelType); walkDirectoryTree(new ModelFoundHandler() { public void handle(Path file) { if (!file.toString().endsWith(fileExtension)) return; allModels.add(getModelContent(file)); }/*w w w .j a v a2 s .c o m*/ }); return allModels; }
From source file:com.dancorder.Archiverify.SynchingVisitor.java
@Override public void preVisitDirectory(Path relativeDirectoryPath, FileExistence existence) { try {//from w w w.j a v a 2 s . com Logger.log("Scanning " + relativeDirectoryPath.toString()); currentRelativeDirectoryPath = relativeDirectoryPath; if (isNotInErrorPath(relativeDirectoryPath)) { errorPath = null; Path directory1 = root1.resolve(relativeDirectoryPath); Path directory2 = root2.resolve(relativeDirectoryPath); Pair<FileHashStore, FileHashStore> hashStorePair = Pair.of( fileHashStoreFactory.createFileHashStore(directory1), fileHashStoreFactory.createFileHashStore(directory2)); hashStoresByDirectory.put(relativeDirectoryPath, hashStorePair); visitedFilesByDirectory.put(relativeDirectoryPath, new ArrayList<Path>()); List<Action> newActions = syncLogic.compareDirectories(directory1, directory2, existence); actions.addAll(newActions); } } catch (Exception e) { errorPath = relativeDirectoryPath; actions.add(new WarningAction( String.format("Error caught visiting directory %s this directory will not be synched. %s", relativeDirectoryPath, e))); } }
From source file:audiomanagershell.commands.FavCommand.java
public FavCommand(Path appPath, Path reference) { super(reference); String OS = System.getProperty("os.name").toLowerCase(); if (OS.equals("windows")) favFile = Paths.get(appPath.toString() + "\\" + "favList.txt"); else/*from w w w .j a v a 2s. c o m*/ favFile = Paths.get(appPath.toString() + "/" + "favList"); }
From source file:com.zergiu.tvman.controllers.FSBrowseController.java
/** * @param children//from w w w . j a v a2 s .co m * @param parent */ private void addParentFolder(Map<String, String> children, Path parent) { Path parentOfParent = parent.getParent(); if (parentOfParent == null) { children.put("", ".."); } else { children.put(parentOfParent.toString(), ".."); } }
From source file:org.elasticsearch.plugins.SitePluginRelativePathConfigIT.java
@Override protected Settings nodeSettings(int nodeOrdinal) { String cwdToRoot = getRelativePath(PathUtils.get(".").toAbsolutePath()); Path pluginDir = PathUtils.get(cwdToRoot, relativizeToRootIfNecessary(getDataPath("/org/elasticsearch/test_plugins")).toString()); Path tempDir = createTempDir(); boolean useRelativeInMiddleOfPath = randomBoolean(); if (useRelativeInMiddleOfPath) { pluginDir = PathUtils.get(tempDir.toString(), getRelativePath(tempDir), pluginDir.toString()); }/*from www. j a va 2 s .c o m*/ return settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put("path.plugins", pluginDir) .put("force.http.enabled", true).build(); }
From source file:org.elasticsearch.plugins.SitePluginRelativePathConfigTests.java
@Override protected Settings nodeSettings(int nodeOrdinal) { String cwdToRoot = getRelativePath(PathUtils.get(".").toAbsolutePath()); Path pluginDir = PathUtils.get(cwdToRoot, relativizeToRootIfNecessary(getDataPath("/org/elasticsearch/plugins")).toString()); Path tempDir = createTempDir(); boolean useRelativeInMiddleOfPath = randomBoolean(); if (useRelativeInMiddleOfPath) { pluginDir = PathUtils.get(tempDir.toString(), getRelativePath(tempDir), pluginDir.toString()); }/* w w w .jav a2s.c o m*/ return settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put("path.plugins", pluginDir) .put("force.http.enabled", true).build(); }
From source file:de.prozesskraft.pkraft.Manager.java
/** * erstellt fuer jeden running step einen watchkey * es soll jedes stepverzeichnis mit dem status 'working' observiert werden bis das file ".exit" erscheint * @param process//from w w w. jav a 2 s . c om * @throws IOException */ private static void createWatchKeysForAllRunningSteps(Process process) throws IOException { // diesen Thread ablegen, damit er vom zyklischen thread gekillt werden kann watcherThread = Thread.currentThread(); // einen neuen map erzeugen fuer die watchKeys keys = new HashMap<WatchKey, Path>(); WatchService watcher = FileSystems.getDefault().newWatchService(); // Anlegen des WatchKeys fuer den Prozess (falls er gestoppt wird, erfolgt die Komunikation mit diesem manager ueber das binaerfile) Path processDir = Paths.get(process.getRootdir()); System.err.println("info: creating a watchkey for the process path " + process.getRootdir()); WatchKey keyProcess = processDir.register(watcher, ENTRY_MODIFY); keys.put(keyProcess, processDir); // Anlegen der WatchKeys fuer jeden laufenden Step for (Step actStep : process.getStep()) { if (actStep.getStatus().equals("working")) { Path stepDir = Paths.get(actStep.getAbsdir()); try { System.err.println("info: step " + actStep.getName() + " is working -> creating a watchkey for its path " + actStep.getAbsdir()); System.err.println("debug: creating..."); WatchKey key = stepDir.register(watcher, ENTRY_CREATE); System.err.println("debug: creating...done. putting to the map"); keys.put(key, stepDir); System.err.println("debug: creating...done. putting to the map...done"); } catch (IOException e) { System.err.println(e); } catch (Exception e) { System.err.println(e); } java.io.File stepDirExitFile = new java.io.File(actStep.getAbsdir() + "/.exit"); java.io.File stepDirStatusFile = new java.io.File(actStep.getAbsdir() + "/.status"); // falls die datei bereits existiert, wird sofort erneut der Prozess weitergeschoben // dies ist dann der fall, wenn ein step gestartet wurde, und danach der manager neu gestartet wurde if (stepDirExitFile.exists()) { System.err.println("info: .exit file already exists -> shortcutting to pushing the process"); // alle keys loeschen keys = null; // den prozess weiter pushen pushProcessAsFarAsPossible(process.getRootdir() + "/process.pmb", false); } // falls der step ein process ist, bibts dort kein .exit file sondern ein .status file else if (stepDirStatusFile.exists()) { System.err.println("info: .status file already exists."); try { java.util.List<String> statusInhalt = Files.readAllLines(stepDirStatusFile.toPath(), Charset.defaultCharset()); if (statusInhalt.size() > 0) { String firstLine = statusInhalt.get(0); System.err.println("info: status changed to: " + firstLine); System.err.println("info: .status file contains status " + firstLine); // wenn ein finaler status, dann soll manager aufgeweckt werden if (firstLine.equals("error") || firstLine.equals("finished")) { System.err.println("info: --> shortcutting to pushing process"); // alle keys loeschen keys = null; // den prozess weiter pushen pushProcessAsFarAsPossible(process.getRootdir() + "/process.pmb", false); } } } catch (IOException e) { // TODO Auto-generated catch block System.err.println( "IOException: trying to read file: " + stepDirStatusFile.getAbsolutePath()); e.printStackTrace(); } catch (ExceptionInInitializerError e) { System.err.println("ExceptionInInitializerError: trying to read file: " + stepDirStatusFile.getAbsolutePath()); e.printStackTrace(); } } } } process.log("info", "now into the watchloop"); // warten auf ein Signal von einem WatchKey for (;;) { WatchKey key; try { key = watcher.take(); } catch (InterruptedException e) { System.err.println(new Timestamp(System.currentTimeMillis()) + ": ---- watcher thread: interrupted! returning to alternativer Thread"); return; } Path dir = keys.get(key); if (dir == null) { System.err.println("WatchKey not recognized!!"); continue; } for (WatchEvent<?> event : key.pollEvents()) { // System.err.println("debug: poll event " + event); WatchEvent.Kind kind = event.kind(); WatchEvent<Path> ev = (WatchEvent<Path>) event; Path name = ev.context(); // dieses logging fuehrt zur aenderung von stderr.txt und .log, was wiederum ein ENTRY_MODIFY ausloest etc. endlosschleife bis platte volllaeuft // System.err.println("debug: poll context " + name); Path child = dir.resolve(name); // System.err.println("debug: poll child " + child); if (kind == ENTRY_CREATE) { if (child.endsWith(".exit")) { System.err.println("info: waking up, because file created: " + child.toString()); // alle keys loeschen keys = null; // den prozess weiter pushen pushProcessAsFarAsPossible(process.getRootdir() + "/process.pmb", false); } } if ((kind == ENTRY_MODIFY) && (child.endsWith("process.pmb"))) { // System.err.println("info: waking up, because process binary file has been modified: " + child.toString()); // alle keys loeschen keys = null; // den prozess weiter pushen pushProcessAsFarAsPossible(process.getRootdir() + "/process.pmb", false); } if (kind == ENTRY_CREATE || kind == ENTRY_MODIFY) { if (child.endsWith(".status")) { try { java.util.List<String> statusInhalt = Files.readAllLines(child, Charset.defaultCharset()); if (statusInhalt.size() > 0) { String firstLine = statusInhalt.get(0); System.err.println("info: status changed to: " + firstLine); // wenn ein finaler status, dann soll manager aufgeweckt werden if (firstLine.equals("error") || firstLine.equals("finished")) { System.err.println("info: waking up, because status changed to: " + firstLine); // alle keys loeschen keys = null; // den prozess weiter pushen pushProcessAsFarAsPossible(process.getRootdir() + "/process.pmb", false); } } } catch (IOException e) { // TODO Auto-generated catch block System.err.println("IOException: trying to read file: " + child.toString()); e.printStackTrace(); } catch (ExceptionInInitializerError e) { System.err.println( "ExceptionInInitializerError: trying to read file: " + child.toString()); e.printStackTrace(); } } } // reset the triggered key key.reset(); } } }
From source file:dk.ekot.misc.SynchronizedCache.java
public void add(Path fullSourcePath, Path fullCachePath) throws IOException { long start = System.nanoTime(); synchronized (fileCopyLockSet) { while (fileCopyLockSet.contains(fullCachePath.toString())) { log.trace("Waiting for " + fullCachePath + " to be removed from lock set"); try { fileCopyLockSet.wait(1000); } catch (InterruptedException e) { log.debug("Interrupted or timed out while waiting for changes in fileCopyLockSet, looking for " + fullCachePath); }// ww w.ja va 2 s . co m log.trace("Interrupted waiting for " + fullCachePath + " after " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) + "ms"); } log.trace("Adding to lock set: " + fullCachePath); fileCopyLockSet.add(fullCachePath.toString()); } try { long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); if (elapsed > 250) { log.warn(String.format("File copy of '%s' delayed %d ms. Possible DDOS.", fullCachePath.toString(), elapsed)); } copy(fullSourcePath, fullCachePath); } finally { log.trace("Removing " + fullCachePath + " from lock set"); // https://docs.oracle.com/javase/tutorial/essential/concurrency/guardmeth.html synchronized (fileCopyLockSet) { fileCopyLockSet.remove(fullCachePath.toString()); fileCopyLockSet.notifyAll(); // Notify waiters } } Path extractedPath = fullSourcePath; cache.put(extractedPath.toString(), fullCachePath); }
From source file:com.marklogic.hub.RestAssetLoader.java
/** * FileVisitor method that loads the file into the modules database if the fileFilter accepts it. */// w ww . j a v a 2 s . com @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException { if (fileFilter.accept(path.toFile())) { Path relPath = currentAssetPath.relativize(path); String uri = "/" + relPath.toString().replace("\\", "/"); if (this.currentRootPath != null) { String name = this.currentRootPath.toFile().getName(); // A bit of a hack to support the special "root" directory. if (!"root".equals(name)) { uri = "/" + name + uri; } } uri = "/ext" + uri; loadFile(uri, path.toFile()); filesLoaded.add(path.toFile()); } return FileVisitResult.CONTINUE; }
From source file:com.spectralogic.ds3cli.command.GetObject.java
@Override public DefaultResult call() throws Exception { final Ds3ClientHelpers helpers = getClientHelpers(); final Path filePath = Paths.get(this.prefix, this.objectName); LOG.info("Output path: {}", filePath.toString()); final Ds3Object ds3Obj; if (this.rangeLength > 0L) { ds3Obj = new PartialDs3Object(this.objectName.replace("\\", "/"), Range.byLength(this.rangeOffset, this.rangeLength)); } else {/*from w w w. ja v a 2 s . c om*/ ds3Obj = new Ds3Object(this.objectName.replace("\\", "/")); } if (this.sync && FileUtils.fileExists(filePath)) { if (SyncUtils.needToSync(helpers, this.bucketName, filePath, ds3Obj.getName(), false)) { this.Transfer(helpers, ds3Obj); return new DefaultResult("SUCCESS: Finished syncing object."); } else { return new DefaultResult("SUCCESS: No need to sync " + this.objectName); } } this.Transfer(helpers, ds3Obj); return new DefaultResult("SUCCESS: " + (this.discard ? "Object retrieved and discarded" : "Finished downloading object. The object was written to: " + filePath)); }