List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:org.wso2.carbon.uuf.renderablecreator.hbs.internal.io.HbsRenderableUpdater.java
public HbsRenderableUpdater() { this.watchingDirectories = new HashSet<>(); this.watchingRenderables = new ConcurrentHashMap<>(); this.watchingExecutables = new ConcurrentHashMap<>(); try {/*w w w .j a v a 2 s . com*/ this.watcher = FileSystems.getDefault().newWatchService(); } catch (IOException e) { throw new FileOperationException("Cannot create file watch service.", e); } this.watchService = new Thread(this::run, HbsRenderableUpdater.class.getName() + "-WatchService"); this.isWatchServiceStopped = false; }
From source file:org.apache.hadoop.hive.ql.log.TestSlidingFilenameRolloverStrategy.java
@Test public void testSlidingLogFiles() throws Exception { assertEquals("bad props file", PROPERTIES_FILE, System.getProperty("log4j.configurationFile")); // Where the log files wll be written Path logTemplate = FileSystems.getDefault().getPath(FILE_PATTERN); String fileName = logTemplate.getFileName().toString(); Path parent = logTemplate.getParent(); try {// w ww . j ava 2 s. c om Files.createDirectory(parent); } catch (FileAlreadyExistsException e) { // OK, fall through. } // Delete any stale log files left around from previous failed tests deleteLogFiles(parent, fileName); Logger logger = LogManager.getLogger(LineageLogger.class); // Does the logger config look correct? org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) logger; LoggerConfig loggerConfig = coreLogger.get(); Map<String, Appender> appenders = loggerConfig.getAppenders(); assertNotNull("sliding appender is missing", appenders.get("sliding")); // Do some logging and force log rollover int NUM_LOGS = 7; logger.debug("Debug Message Logged !!!"); logger.info("Info Message Logged !!!"); String errorString = "Error Message Logged "; for (int i = 0; i < NUM_LOGS; i++) { TimeUnit.MILLISECONDS.sleep(100); // log an exception - this produces enough text to force a new logfile // (as appender.sliding.policies.size.size=1KB) logger.error(errorString + i, new RuntimeException("part of a test")); } // Check log files look OK DirectoryStream<Path> stream = Files.newDirectoryStream(parent, fileName + ".*"); int count = 0; for (Path path : stream) { count++; String contents = new String(Files.readAllBytes(path), "UTF-8"); // There should be one exception message per file assertTrue("File " + path + " did not have expected content", contents.contains(errorString)); String suffix = StringUtils.substringAfterLast(path.toString(), "."); // suffix should be a timestamp try { long timestamp = Long.parseLong(suffix); } catch (NumberFormatException e) { fail("Suffix " + suffix + " is not a long"); } } assertEquals("bad count of log files", NUM_LOGS, count); // Check there is no log file without the suffix assertFalse("file should not exist:" + logTemplate, Files.exists(logTemplate)); // Clean up deleteLogFiles(parent, fileName); }
From source file:com.gwac.job.FileTransferServiceImpl.java
void test() { try {//from w w w .j av a2 s. c o m System.out.println("123"); watcher = FileSystems.getDefault().newWatchService(); Path dir = Paths.get("E:/TestData/gwacTest"); dir.register(watcher, ENTRY_CREATE, ENTRY_MODIFY); System.out.println("Watch Service registered for dir: " + dir.getFileName()); isSuccess = true; } catch (IOException ex) { isSuccess = false; ex.printStackTrace(); } }
From source file:com.kappaware.logtrawler.DirWatcher.java
/** * //from www . java 2s. c om * @param path The path to monitor * @param queue Where to store events * @throws IOException */ DirWatcher(Config.Agent.Folder dir, BlockingSetQueue<FileEvent> queue) throws IOException { Path path = Paths.get(dir.getPath()); this.followLink = dir.getFollowLink(); this.queue = queue; this.watcher = FileSystems.getDefault().newWatchService(); this.pathByKey = new HashMap<WatchKey, Path>(); this.fileVisitOptions = new HashSet<FileVisitOption>(); if (this.followLink) { this.fileVisitOptions.add(FileVisitOption.FOLLOW_LINKS); } if (dir.getExcludedPaths() != null && dir.getExcludedPaths().size() > 0) { exclusions = new Vector<Exclusion>(dir.getExcludedPaths().size()); for (String excludedPath : dir.getExcludedPaths()) { exclusions.add(new Exclusion(dir.getPath(), excludedPath)); } } log.info(String.format("Scanning %s ...", path)); this.registerWithSub(path, FileEvent.Type.FILE_INIT); this.watcherThread = new WatcherThread(); this.watcherThread.setDaemon(true); this.watcherThread.start(); }
From source file:api.reader.LuceneIndexReader.java
/** * This is called as a part of the startup for the startup. * When running an application that is on the web application, the api.reader is started by the startup script. * * @param filename The index directory//from ww w . jav a2 s. c o m * @return if the index initialization succeeds return true. */ @Override public boolean initializeIndexReader(String filename) { try { READER = DirectoryReader.open(FSDirectory.open(FileSystems.getDefault().getPath(filename))); } catch (IOException e) { READER = null; log.error("Failed to instantiate the index api.reader with directory: " + filename); } return isInitialized(); }
From source file:ConcurrentTest.java
@Test public void allAlgorithmsNewConcurrent() throws NoSuchAlgorithmException, InterruptedException, ExecutionException, IOException { List<Algorithm> algorithms = IMAGE_FILE_RESULTS.keySet().stream() .map(algorithmName -> Algorithm.getAlgorithm(algorithmName)).collect(Collectors.toList()); Path path = FileSystems.getDefault().getPath(JacksonJacksumTest.class.getResource("/image.jpg").getFile()); for (Map.Entry<Pair<Path, Algorithm>, byte[]> e : new ConcurrentHasher() .hashFiles(Collections.singletonList(path), algorithms, false, Collections.emptyList()) .entrySet()) {//from ww w .ja v a 2s . c o m String expected = IMAGE_FILE_RESULTS.get(e.getKey().getSecond().getCanonicalName()).getValue(); String actual = Encoding.HEX.encode(-1, ' ', e.getValue()); assertEquals(expected, actual); } }
From source file:org.cryptomator.ui.settings.SettingsProvider.java
private Path getSettingsPath() throws IOException { final String settingsPathProperty = System.getProperty("cryptomator.settingsPath"); return Optional.ofNullable(settingsPathProperty).filter(StringUtils::isNotBlank).map(this::replaceHomeDir) .map(FileSystems.getDefault()::getPath).orElse(DEFAULT_SETTINGS_PATH); }
From source file:io.mangoo.build.Watcher.java
@SuppressWarnings("all") public Watcher(Set<Path> watchDirectory, Set<String> includes, Set<String> excludes, Trigger trigger) throws IOException { this.watchService = FileSystems.getDefault().newWatchService(); this.watchKeys = new HashMap<>(); this.includes = includes; //NOSONAR this.excludes = excludes; //NOSONAR this.trigger = trigger; this.takeCount = new AtomicInteger(0); for (Path path : watchDirectory) { registerAll(path);/*from ww w .j a v a 2s. c om*/ } }
From source file:org.ng200.openolympus.resourceResolvers.OpenOlympusMessageSource.java
private void reportMissingLocalisationKey(final String code) { try {/*from w w w. ja va2 s.c o m*/ if (code.isEmpty() || Character.isUpperCase(code.charAt(0))) { return; } final Path file = FileSystems.getDefault().getPath(this.storagePath, "missingLocalisation.txt"); if (!FileAccess.exists(file)) { FileAccess.createDirectories(file.getParent()); FileAccess.createFile(file); } final Set<String> s = new TreeSet<>(Arrays.asList(FileAccess.readUTF8String(file).split("\n"))); s.add(code); FileAccess.writeUTF8StringToFile(file, s.stream().collect(Collectors.joining("\n"))); } catch (final IOException e) { OpenOlympusMessageSource.logger.error("Couldn't add to missing key repo: {}", e); } }
From source file:de.digiway.rapidbreeze.server.infrastructure.objectstorage.ObjectStorage.java
/** * Creates a new instance of the object storage using the given location as * storage point./*from ww w . j a v a 2 s .c o m*/ * * @param storageLocation */ public ObjectStorage(Path storageLocation) { if (storageLocation == null) { throw new IllegalArgumentException( "Cannot use path:" + storageLocation + " as storage location for objects."); } try { if (!Files.exists(storageLocation)) { Files.createDirectories(storageLocation); } this.root = storageLocation; this.fileSystem = FileSystems.getDefault(); this.classMap = getStorageMap(CLASSMAP_FILENAME); } catch (IOException ex) { throw new IllegalStateException(ex); } }