List of usage examples for java.nio.file Path getFileSystem
FileSystem getFileSystem();
From source file:org.brekka.stillingar.spring.snapshot.WatchedResourceMonitor.java
@Override public void initialise(Resource resource) { try {/*from w w w . j a v a2s . co m*/ this.resourceFile = resource.getFile().toPath(); Path parent = resourceFile.getParent(); this.watchService = parent.getFileSystem().newWatchService(); this.watchKey = parent.register(this.watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE); } catch (IOException e) { throw new ConfigurationException( String.format("Failed to initialize watcher for resource '%s'", resource.toString()), e); } }
From source file:org.elasticsearch.plugins.SitePluginRelativePathConfigIT.java
private String getRelativePath(Path path) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < path.getNameCount(); i++) { sb.append(".."); sb.append(path.getFileSystem().getSeparator()); }//from w ww. j a v a 2 s. c om return sb.toString(); }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemPath.java
@Override public int compareTo(Path other) { if (!fileSystem.equals(other.getFileSystem())) throw new IllegalArgumentException(); return base.compareTo(((HadoopFileSystemPath) other).base); }
From source file:acromusashi.stream.ml.common.spout.WatchTextBatchSpout.java
/** * ???????????????????/* w w w .j a va2s .c o m*/ * * @param collector Collector * @throws IOException * @throws InterruptedException ? */ @SuppressWarnings({ "rawtypes" }) protected void checkDataFile(TridentCollector collector) throws IOException, InterruptedException { // ????????????????? if (this.isInitialReaded == false) { List<String> fileContents = FileUtils.readLines(this.targetFile); emitTuples(fileContents, collector); this.isInitialReaded = true; // Path dirPath = new File(this.dataFileDir).toPath(); FileSystem fileSystem = dirPath.getFileSystem(); this.watcherService = fileSystem.newWatchService(); this.watchKey = dirPath.register(this.watcherService, new Kind[] { StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY }); return; } // ???????? WatchKey detectedKey = this.watcherService.poll(1, TimeUnit.SECONDS); // ??????????????????????? if (detectedKey == null || detectedKey.equals(this.watchKey) == false) { return; } try { // ??????????????? for (WatchEvent event : detectedKey.pollEvents()) { Path filePath = (Path) event.context(); // ????????????? if (filePath == null || this.targetFile.toPath().getFileName().equals(filePath.getFileName()) == false) { continue; } List<String> fileContents = FileUtils.readLines(this.targetFile); emitTuples(fileContents, collector); } } finally { detectedKey.reset(); } }
From source file:codes.writeonce.maven.plugins.soy.CompileMojo.java
private Path getJavaSourceOutputPath() { final Path javaOutputPath = javaOutputDirectory.toPath(); final Path javapackageSubpath = javaOutputPath.getFileSystem().getPath("", javaPackage.split("\\.")); return javaOutputPath.resolve(javapackageSubpath); }
From source file:com.spotify.helios.servicescommon.PersistentAtomicReference.java
private PersistentAtomicReference(final Path filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { try {/* w w w . j av a2s. c o m*/ this.filename = filename.toAbsolutePath(); this.tempfilename = filename.getFileSystem().getPath(this.filename.toString() + ".tmp"); if (Files.exists(filename)) { final byte[] bytes = Files.readAllBytes(filename); if (bytes.length > 0) { value = Json.read(bytes, javaType); } else { value = initialValue.get(); } } else { value = initialValue.get(); } } catch (InterruptedIOException | ClosedByInterruptException e) { throw new InterruptedException(e.getMessage()); } }
From source file:io.gravitee.gateway.services.localregistry.LocalApiDefinitionRegistry.java
@Override protected void doStart() throws Exception { if (enabled) { super.doStart(); this.init(); executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "registry-monitor")); executor.execute(() -> {/*ww w.j a v a 2s.c o m*/ Path registry = Paths.get(registryPath); LOGGER.info("Start local registry monitor for directory {}", registry); try { WatchService watcher = registry.getFileSystem().newWatchService(); registry.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); while (true) { WatchKey key; try { key = watcher.take(); } catch (InterruptedException ex) { return; } for (WatchEvent<?> event : key.pollEvents()) { WatchEvent.Kind<?> kind = event.kind(); @SuppressWarnings("unchecked") WatchEvent<Path> ev = (WatchEvent<Path>) event; Path fileName = registry.resolve(ev.context().getFileName()); LOGGER.info("An event occurs for file {}: {}", fileName, kind.name()); if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { Api loadedDefinition = loadDefinition(fileName.toFile()); Api existingDefinition = definitions.get(fileName); if (existingDefinition != null) { if (apiManager.get(existingDefinition.getId()) != null) { apiManager.update(loadedDefinition); } else { apiManager.undeploy(existingDefinition.getId()); definitions.remove(fileName); apiManager.deploy(loadedDefinition); definitions.put(fileName, loadedDefinition); } } } else if (kind == StandardWatchEventKinds.ENTRY_CREATE) { Api loadedDefinition = loadDefinition(fileName.toFile()); Api existingDefinition = apiManager.get(loadedDefinition.getId()); if (existingDefinition != null) { apiManager.update(loadedDefinition); } else { apiManager.deploy(loadedDefinition); definitions.put(fileName, loadedDefinition); } } else if (kind == StandardWatchEventKinds.ENTRY_DELETE) { Api existingDefinition = definitions.get(fileName); if (existingDefinition != null && apiManager.get(existingDefinition.getId()) != null) { apiManager.undeploy(existingDefinition.getId()); definitions.remove(fileName); } } boolean valid = key.reset(); if (!valid) { break; } } } } catch (IOException ioe) { LOGGER.error("Unexpected error while looking for PI definitions from filesystem", ioe); } }); } }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java
@Override public FileStore getFileStore(Path path) throws IOException { for (FileStore fs : path.getFileSystem().getFileStores()) { return fs; }/* w ww . ja va 2s . c o m*/ return null; }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java
@Override public boolean isHidden(Path path) throws IOException { FileSystem fs = path.getFileSystem(); if (!HadoopFileSystem.class.isInstance(fs)) throw new IllegalArgumentException("path"); try {/* ww w. ja va2 s . c om*/ return readAttributes(path, HadoopFileAttributes.class).isHidden(); } catch (RemoteException e) { rethrowRemoteException(e, path); return false; } }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java
public void delete(Path path, boolean recursive) throws IOException { FileSystem fs = path.getFileSystem(); if (!HadoopFileSystem.class.isInstance(fs)) throw new IllegalArgumentException("path"); try {// w w w . j a va 2s.co m ((HadoopFileSystem) fs).delete(path, recursive); } catch (RemoteException e) { rethrowRemoteException(e, path); } }