List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:bjerne.gallery.service.impl.GalleryRootDirConfigJob.java
@PostConstruct public void setUp() throws IOException { watcher = FileSystems.getDefault().newWatchService(); // Initial loading updateConfigFromFile();/* w ww. j av a 2 s . co m*/ // Kick of watcher thread Runnable fileWatcher = () -> { watchForChanges(); }; new Thread(fileWatcher).start(); ; }
From source file:org.dataconservancy.dcs.util.FilePathUtil.java
/** * This method has been deprecated use the Java Path relativize method instead. * Strips the base directory out of a file path to make a relative file path. If the file doesn't contain the base path the original path is returned. * @param basePath The base directory path to remove from the file path. * @param toRelativize The file to be made relative. * @return The relative file path created by removing the base directory. Returns null if the file to relative is null. *///from w w w . j a va 2s. c o m @Deprecated public static String relativizePath(String basePath, File toRelativize) { if (toRelativize == null) { return null; } if (basePath == null || !toRelativize.getPath().startsWith(basePath)) { return toRelativize.getPath(); } Path path = FileSystems.getDefault().getPath(basePath); Path relativePath = path.relativize(toRelativize.toPath()); return relativePath.toString(); }
From source file:org.ballerinalang.composer.service.fs.LocalFileSystem.java
@Override public JsonArray listRoots(List<String> extensionList) throws IOException { final Iterable<Path> rootDirs = FileSystems.getDefault().getRootDirectories(); List<Path> rootDirsList = new ArrayList<>(); rootDirs.forEach(rootDirsList::add); return getJsonArrayForDirs(rootDirsList, extensionList); }
From source file:uk.co.flax.harahachibu.services.impl.SolrDiskSpaceChecker.java
@Override public void configure(Map<String, Object> configuration) throws DiskSpaceCheckerException { final String dataPath = (String) configuration.get(DATA_DIR_CONFIG_OPTION); if (StringUtils.isBlank(dataPath)) { throw new DiskSpaceCheckerException("No data directory given for Solr disk space checker"); } else {// w w w .j a v a2s . c om try { // Set up the FileStore Path path = FileSystems.getDefault().getPath(dataPath); fs = Files.getFileStore(path); } catch (IOException e) { LOGGER.error("IO Exception initialising file store: {}", e.getMessage()); throw new DiskSpaceCheckerException(e); } } }
From source file:es.molabs.io.utils.test.FileWatcherRunnableTest.java
@Test public void testEntryModify() throws Throwable { URL file = getClass().getResource("/es/molabs/io/utils/test/filewatcher/test.txt"); WatchService watchService = FileSystems.getDefault().newWatchService(); FileWatcherHandler handler = Mockito.mock(FileWatcherHandler.class); FileWatcherRunnable fileWatcherRunnable = new FileWatcherRunnable(watchService, handler); fileWatcherRunnable.addFile(file);//from www . ja va 2 s. c o m executor.submit(fileWatcherRunnable); // Writes to the file FileUtils.write(new File(file.getFile()), "test data.", Charset.defaultCharset()); // Waits the refresh time Thread.sleep(fileWatcherRunnable.getRefreshTime() + REFRESH_MARGIN); // Checks that the event handler has been called one time Mockito.verify(handler, Mockito.times(1)).entryModify(Mockito.any()); // Stops the service watchService.close(); }
From source file:org.wso2.carbon.uuf.renderablecreator.hbs.internal.io.RenderableUpdater.java
public RenderableUpdater() { this.watchingDirectories = new HashSet<>(); this.watchingRenderables = new ConcurrentHashMap<>(); this.watchingExecutables = new ConcurrentHashMap<>(); try {//from ww w . j a v a 2s. c o m this.watcher = FileSystems.getDefault().newWatchService(); } catch (IOException e) { throw new FileOperationException("Cannot create file watch service.", e); } this.watchService = new Thread(this::run, RenderableUpdater.class.getName() + "-WatchService"); this.isWatchServiceStopped = false; }
From source file:org.apache.logging.log4j.core.appender.rolling.RollingAppenderDirectWriteTempCompressedFilePatternTest.java
@Test public void testAppender() throws Exception { final File dir = new File(DIR); dir.mkdirs();/*from w ww .ja va2 s . c om*/ try (final WatchService watcher = FileSystems.getDefault().newWatchService()) { WatchKey key = dir.toPath().register(watcher, StandardWatchEventKinds.ENTRY_CREATE); for (int i = 0; i < 100; ++i) { logger.debug("This is test message number " + i); } Thread.sleep(50); assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0); final File[] files = dir.listFiles(); assertNotNull(files); assertThat(files, hasItemInArray(that(hasName(that(endsWith(".gz")))))); int temporaryFilesCreated = 0; int compressedFiles = 0; key = watcher.take(); for (final WatchEvent<?> event : key.pollEvents()) { final WatchEvent<Path> ev = (WatchEvent<Path>) event; final Path filename = ev.context(); if (filename.toString().endsWith(".tmp")) { temporaryFilesCreated++; } if (filename.toString().endsWith(".gz")) { compressedFiles++; } } assertTrue("No temporary file created during compression", temporaryFilesCreated > 0); assertTrue("Temporarys file created not equals to compressed files", compressedFiles == temporaryFilesCreated); } }
From source file:com.qwazr.compiler.JavaCompiler.java
static JavaCompiler newInstance(ExecutorService executorService, File javaSourceDirectory, File javaClassesDirectory, File... classPathDirectories) throws IOException, URISyntaxException { Objects.requireNonNull(javaSourceDirectory, "No source directory given (null)"); Objects.requireNonNull(javaClassesDirectory, "No class directory given (null)"); final FileSystem fs = FileSystems.getDefault(); final List<URL> urlList = new ArrayList<URL>(); urlList.add(javaClassesDirectory.toURI().toURL()); final String classPath = buildClassPath(classPathDirectories, urlList); return new JavaCompiler(executorService, javaSourceDirectory, javaClassesDirectory, classPath, urlList); }
From source file:org.ng200.openolympus.services.TaskContainerCache.java
public TaskContainer getTaskContainerForTask(final Task task) { if (this.sharedTemporaryStorageFactory == null) { this.sharedTemporaryStorageFactory = new SharedTemporaryStorageFactory( FileSystems.getDefault().getPath(this.storageService.getStoragePath())); }//from w ww .java2 s . c om return this.taskContainers.computeIfAbsent(task, (key) -> { try { return new TaskContainer(this.storageService.getTaskJudgeFile(task), this.sharedTemporaryStorageFactory, this.executorService); } catch (final Exception e) { throw new RuntimeException("Couldn't load task container", e); } }); }
From source file:com.ibm.vicos.client.ClientCommand.java
@CliCommand(value = "getblob", help = "Downloads a blob to destination path") public String getBlob( @CliOption(key = { "container" }, mandatory = true, help = "container name") final String container, @CliOption(key = { "blob" }, mandatory = true, help = "blob name") final String blob, @CliOption(key = { "dest_path" }, mandatory = true, help = "destination path") final String path) { Path fullPath = FileSystems.getDefault().getPath(path, blob); fullPath.getParent().toFile().mkdirs(); try {/*from w w w. j av a 2 s . com*/ InputStream inputStream = storage.getObject(container, blob); OutputStream outputStream = new FileOutputStream(fullPath.toFile()); long total = ByteStreams.copy(inputStream, outputStream); checkState(fullPath.toFile().exists(), "Could not create file"); return "Successfully downloaded " + fullPath.toString() + " [" + total + " bytes]"; } catch (Exception e) { e.printStackTrace(); return "Error while getting the " + container + "/" + blob; } }