List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:nl.uva.contextualsuggestion.Ranker_2014.java
public Ranker_2014() throws IOException { indexPathString = configFile.getProperty("INDEX_PATH"); ipath = FileSystems.getDefault().getPath(indexPathString); ireader = DirectoryReader.open(FSDirectory.open(ipath)); iInfo = new IndexInfo(ireader); }
From source file:com.yahoo.maven.visitor.VisitorGenerator.java
public void generate() throws IOException { for (Visitor visitor : getVisitors()) { String name = visitor.getVisitedName(); int packageTail = name.lastIndexOf("."); String aPackage = packageTail == -1 ? null : name.substring(0, packageTail); String disjunctName = packageTail == -1 ? name : name.substring(packageTail + 1, name.length()); String className = capitalizer.capitalize(disjunctName); String dir = aPackage == null ? "" : StringUtils.replace(aPackage, ".", FileSystems.getDefault().getSeparator()); List<TypeParameterContext> typeParameterContexts = new ArrayList<>(); Set<String> typeParameterNames = new LinkedHashSet<>(); if (visitor.getTypeParameters() != null) { typeParameterContexts.addAll(Arrays.asList(visitor.getTypeParameters())); for (TypeParameter typeParameter : visitor.getTypeParameters()) { typeParameterNames.add(typeParameter.getName()); }//from ww w .j a v a 2 s . c o m } List<DisjunctContext> disjuncts = new ArrayList<>(); for (Disjunction disjunction : visitor.getDisjunctions()) { List<ParameterContext> parameterContexts = new ArrayList<>(); if (disjunction.parameters != null) { for (Parameter parameter : disjunction.parameters) { parameterContexts.add(new ParameterContext() { @Override public String getType() { return parameter.type; } @Override public String getName() { return parameter.name; } @Override public String getHashExpression() { switch (getType()) { case "boolean": return "(" + getName() + " ? 1 : 0)"; case "char": case "byte": case "short": return "(int) " + getName(); case "int": return getName(); case "long": return "(int) (" + getName() + " ^ (" + getName() + " >>> 32))"; case "float": return "(" + getName() + " != +0.0f ? Float.floatToIntBits(" + getName() + ") : 0)"; case "double": return "(int) (Double.doubleToLongBits(" + getName() + ") ^ (Double.doubleToLongBits(" + getName() + ") >>> 32))"; default: return "(" + getName() + " != null ? " + getName() + ".hashCode() : 0)"; } } }); } } disjuncts.add(new DisjunctContext() { @Override public String getMethodName() { return disjunction.name; } @Override public List<ParameterContext> getParameters() { return parameterContexts.isEmpty() ? null : parameterContexts; } @Override public boolean hasAsMethod() { return parameterContexts.size() == 1 && !primitives.contains(parameterContexts.get(0).getType()); } }); } class AbstractBaseContext implements BaseContext { @Override public String getPackage() { return aPackage; } @Override public String getVisitedClassName() { return className; } @Override public List<TypeParameterContext> getTypeParameters() { return typeParameterContexts.isEmpty() ? null : typeParameterContexts; } @Override public List<DisjunctContext> getDisjuncts() { return disjuncts.isEmpty() ? null : disjuncts; } } Path outputFolder = getOutputDirectory().resolve(dir); File outputFolderAsFile = outputFolder.toFile(); if (!outputFolderAsFile.mkdirs() && !outputFolderAsFile.exists()) { throw new IOException("Unable to make directory: " + outputFolderAsFile.getAbsolutePath()); } try (Writer visitedWriter = Files.newBufferedWriter(outputFolder.resolve(className + ".java"))) { class ThisVisitedContext extends AbstractBaseContext implements VisitedContext { } visitedTemplate.merge(visitedWriter, new ThisVisitedContext()); } try (Writer visitorWriter = Files.newBufferedWriter(outputFolder.resolve(className + "Visitor.java"))) { class ThisVisitorContext extends AbstractBaseContext implements VisitorContext { } visitorTemplate.merge(visitorWriter, new ThisVisitorContext()); } try (Writer visitorWriter = Files .newBufferedWriter(outputFolder.resolve("Defaulting" + className + "Visitor.java"))) { class ThisDefaultingVisitorContext extends AbstractBaseContext implements DefaultingVisitorContext { } defaultingVisitorTemplate.merge(visitorWriter, new ThisDefaultingVisitorContext()); } try (Writer visitorWriter = Files .newBufferedWriter(outputFolder.resolve("Identity" + className + "Visitor.java"))) { class ThisIdentityVisitorContext extends AbstractBaseContext implements IdentityVisitorContext { } identityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext()); } try (Writer visitorWriter = Files .newBufferedWriter(outputFolder.resolve("DefaultingIdentity" + className + "Visitor.java"))) { class ThisIdentityVisitorContext extends AbstractBaseContext implements IdentityVisitorContext, DefaultingVisitorContext { } defaultingIdentityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext()); } } }
From source file:com.acmutv.ontoqa.tool.io.IOManager.java
/** * Returns an {@link OutputStream} from a general resource. * @param resource the resource locator (e.g.: path for local file, http url for remote file). * @return the open {@link OutputStream}. * @throws IOException when the {@link OutputStream} cannot be opened. *///from w w w.j a va 2s . c o m public static OutputStream getOutputStream(final String resource) throws IOException { final Path path = FileSystems.getDefault().getPath(resource).toAbsolutePath(); return Files.newOutputStream(path); }
From source file:com.xiaomi.linden.common.util.FileChangeWatcher.java
@Override public void run() { try {/*from w ww. j a va2 s . c o m*/ watcher = FileSystems.getDefault().newWatchService(); Path path = new File(absolutePath).toPath().getParent(); String fileWatched = FilenameUtils.getName(absolutePath); path.register(watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_MODIFY }, SensitivityWatchEventModifier.HIGH); LOGGER.info("File watcher start to watch {}", absolutePath); while (isAlive()) { try { Thread.sleep(interval); WatchKey key = watcher.poll(1000l, TimeUnit.MILLISECONDS); if (key == null) { continue; } List<WatchEvent<?>> events = key.pollEvents(); for (WatchEvent<?> event : events) { if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { String file = event.context().toString(); if (fileWatched.equals(file)) { doOnChange(); } } } if (!key.reset()) { LOGGER.info("File watcher key not valid."); } } catch (InterruptedException e) { LOGGER.error("File watcher thread exit!"); break; } } } catch (Throwable e) { LOGGER.error("File watcher error {}", Throwables.getStackTraceAsString(e)); } }
From source file:com.zergiu.tvman.controllers.FSBrowseController.java
@RequestMapping(value = "/children", method = RequestMethod.POST) public @ResponseBody Map<String, String> getChildren( @RequestParam(value = "parentPath", required = false) String parentPath) { Map<String, String> children = new TreeMap<String, String>(); if (parentPath == null || "".equals(parentPath)) { addRootPaths(children);/*from w w w . jav a 2s. co m*/ } else { try { Path parent = FileSystems.getDefault().getPath(parentPath); addParentFolder(children, parent); addChildFolders(children, parent); } catch (IOException e) { e.printStackTrace(); log.error(e.getMessage(), e); } } log.debug("got files " + children); return children; }
From source file:com.streamsets.extra.DockerMetadataCache.java
public DockerMetadataCache(String base, String file) { this.basePath = base; this.filename = file; CacheLoader<String, Map> loader = new CacheLoader<String, Map>() { private final ObjectMapper mapper = new ObjectMapper(); @Override//from ww w . j av a 2s . c o m public Map load(String key) throws Exception { FileSystem fs = FileSystems.getDefault(); Path path = fs.getPath(basePath, key, filename); final String contents = new String(Files.readAllBytes(path), Charset.forName("UTF-8")); return mapper.readValue(contents, HashMap.class); } }; cache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000).build(loader); }
From source file:com.liferay.sync.engine.util.FileUtilTest.java
@Test public void testGetFilePathName() { FileSystem fileSystem = FileSystems.getDefault(); Assert.assertEquals("test" + fileSystem.getSeparator() + "test", FileUtil.getFilePathName("test", "test")); }
From source file:io.github.mbarre.schemacrawler.tool.linter.BaseLintTest.java
protected List<LintWrapper> executeToJsonAndConvertToLintList(SchemaCrawlerOptions options, Connection connection) throws Exception { final Executable executable = new SchemaCrawlerExecutable("lint"); final Path linterConfigsFile = FileSystems.getDefault().getPath("", this.getClass().getClassLoader().getResource("schemacrawler-linter-configs-test.xml").getPath()); final LintOptionsBuilder optionsBuilder = new LintOptionsBuilder(); optionsBuilder.withLinterConfigs(linterConfigsFile.toString()); executable.setAdditionalConfiguration(optionsBuilder.toConfig()); Path out = Paths.get("target/test_" + this.getClass().getSimpleName() + ".json"); OutputOptions outputOptions = new OutputOptions(TextOutputFormat.json, out); outputOptions.setOutputFile(Paths.get("target/test_" + this.getClass().getSimpleName() + ".json")); executable.setOutputOptions(outputOptions); executable.setSchemaCrawlerOptions(options); executable.execute(connection);// w ww . ja v a2 s . co m File output = new File(out.toString()); String data = IOUtils.toString(new FileInputStream(output)); Assert.assertNotNull(data); JSONObject json = new JSONObject(data.toString().substring(1, data.toString().length() - 2)); List<LintWrapper> lints = new ArrayList<>(); if (json.get("table_lints") instanceof JSONObject) { Assert.assertNotNull(json.getJSONObject("table_lints")); JSONArray jsonLints = json.getJSONObject("table_lints").getJSONArray("lints"); Assert.assertNotNull(jsonLints); if (options.getTableNamePattern() != null && !options.getTableNamePattern().isEmpty()) Assert.assertEquals(options.getTableNamePattern(), json.getJSONObject("table_lints").getString("name")); for (int i = 0; i < jsonLints.length(); i++) { if (!"databasechangelog".equals(json.getJSONObject("table_lints").getString("name")) && !"databasechangeloglock".equals(json.getJSONObject("table_lints").getString("name"))) lints.add(createLintWrapper(json.getJSONObject("table_lints").getString("name"), jsonLints.getJSONObject(i))); } } else { Assert.assertNotNull(json.getJSONArray("table_lints")); JSONArray jsonTableLints = json.getJSONArray("table_lints"); for (int i = 0; i < jsonTableLints.length(); i++) { JSONArray jsonLints = jsonTableLints.getJSONObject(i).getJSONArray("lints"); Assert.assertNotNull(jsonLints); if (options.getTableNamePattern() != null && !options.getTableNamePattern().isEmpty()) Assert.assertEquals(options.getTableNamePattern(), json.getJSONObject("table_lints").getString("name")); for (int j = 0; j < jsonLints.length(); j++) { if (!"databasechangelog".equals(jsonTableLints.getJSONObject(i).getString("name")) && !"databasechangeloglock".equals(jsonTableLints.getJSONObject(i).getString("name"))) lints.add(createLintWrapper(jsonTableLints.getJSONObject(i).getString("name"), jsonLints.getJSONObject(j))); } } } return lints; }
From source file:io.stallion.fileSystem.FileSystemWatcherRunner.java
public FileSystemWatcherRunner(boolean isCodeWatcher) { try {//from www. j a v a2 s .c o m watcher = FileSystems.getDefault().newWatchService(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.ballerinalang.composer.service.workspace.local.LocalFSWorkspace.java
@Override public JsonArray listRoots() throws IOException { final Iterable<Path> rootDirs = FileSystems.getDefault().getRootDirectories(); List<Path> rootDirsList = new ArrayList<>(); rootDirs.forEach(rootDirsList::add); return getJsonArrayForDirs(rootDirsList); }