List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:org.cryptomator.ui.MainApplication.java
void handleCommandLineArg(final MainController ctrl, String arg) { Path file = FileSystems.getDefault().getPath(arg); if (!Files.exists(file)) { try {/*from w w w . ja v a2 s. co m*/ if (!Files.isDirectory(Files.createDirectories(file))) { return; } } catch (IOException e) { return; } // directory created. } else if (Files.isRegularFile(file)) { if (StringUtils.endsWithIgnoreCase(file.getFileName().toString(), Aes256Cryptor.MASTERKEY_FILE_EXT)) { file = file.getParent(); } else { // is a file, but not a masterkey file return; } } Path f = file; Platform.runLater(() -> { ctrl.addDirectory(f); ctrl.toFront(); }); }
From source file:com.spectralogic.ds3cli.command.GetBulk.java
@Override public CliCommand init(final Arguments args) throws Exception { processCommandOptions(requiredArgs, optionalArgs, args); this.bucketName = args.getBucket(); this.priority = args.getPriority(); this.numberOfThreads = args.getNumberOfThreads(); this.directory = args.getDirectory(); if (Guard.isStringNullOrEmpty(this.directory) || directory.equals(".")) { this.outputPath = FileSystems.getDefault().getPath("."); } else {/*from w w w. j a v a2s . c o m*/ final Path dirPath = FileSystems.getDefault().getPath(directory); this.outputPath = FileSystems.getDefault().getPath(".").resolve(dirPath); } LOG.info("Output Path = {}", this.outputPath); this.discard = args.isDiscard(); if (this.discard && !Guard.isStringNullOrEmpty(directory)) { throw new CommandException("Cannot set both directory and --discard"); } if (this.discard) { LOG.warn("Using /dev/null getter -- all incoming data will be discarded"); } this.pipe = CliUtils.isPipe(); if (this.pipe) { if (this.isOtherArgs(args)) { throw new BadArgumentException( "--discard, -o and -p arguments are not supported when using piped input"); } this.pipedFileNames = FileUtils.getPipedListFromStdin(getFileSystemProvider()); if (Guard.isNullOrEmpty(this.pipedFileNames)) { throw new MissingOptionException("Stdin is empty"); //We should never see that since we checked isPipe } } else { final String[] prefix = args.getOptionValues(PREFIXES.getOpt()); if (prefix != null && prefix.length > 0) { this.prefixes = ImmutableList.copyOf(prefix); } } if (args.isSync()) { LOG.info("Using sync command"); this.sync = true; } return this; }
From source file:com.acmutv.ontoqa.tool.io.IOManager.java
/** * Checks if {@code resource} is a regular file. * @param resource the resource to check. * @return true if {@code resource} is a regular file; else, otherwise. *//*w w w . java2 s. c om*/ public static boolean isFile(String resource) { final Path path = FileSystems.getDefault().getPath(resource).toAbsolutePath(); return Files.isRegularFile(path); }
From source file:nl.uva.contextualsuggestion.Ranker.java
public void main() throws FileNotFoundException, IOException { File f = new File("response.json"); f.delete();// w ww .j ava 2 s .c om File f2 = new File("response-treceval.res"); f2.delete(); String field = "TEXT"; indexPathString = configFile.getProperty("INDEX_PATH"); ipath = FileSystems.getDefault().getPath(indexPathString); ireader = DirectoryReader.open(FSDirectory.open(ipath)); iInfo = new IndexInfo(ireader); CollectionSLM CLM = new CollectionSLM(ireader, field); String inputProfiles = configFile.getProperty("USERS"); String line = null; BufferedReader br = new BufferedReader(new FileReader(inputProfiles)); Integer cnt = 1; while ((line = br.readLine()) != null) { User user = this.GetUserInfo(line); HashMap<String, Double> scores1 = new HashMap<>(); HashMap<String, Double> scores2 = new HashMap<>(); for (String candidate : user.suggestionCandidates) { Integer indexId = iInfo.getIndexId(candidate); LanguageModel candidateSLM = new StandardLM(ireader, indexId, field); SmoothedLM candidateSLM_smoothed = new SmoothedLM(candidateSLM, CLM); SmoothedLM PM_PLMsmoothed = new SmoothedLM(user.userPositiveMixturePLM, CLM); SmoothedLM NM_PLMsmoothed = new SmoothedLM(user.userNegativeMixturePLM, CLM); SmoothedLM PT_PLMsmoothed = new SmoothedLM(user.userPositiveMixtureTags, CLM); SmoothedLM NT_PLMsmoothed = new SmoothedLM(user.userNegativeMixtureTags, CLM); Divergence div1 = new Divergence(candidateSLM_smoothed, PM_PLMsmoothed); Double score1 = div1.getJsdSimScore(); // Divergence div2 = new Divergence(candidateSLM_smoothed, NM_PLMsmoothed); // Double score2 = div2.getJsdSimScore(); Divergence div3 = new Divergence(candidateSLM_smoothed, PT_PLMsmoothed); Double score3 = div3.getJsdSimScore(); // Divergence div4 = new Divergence(candidateSLM_smoothed, NT_PLMsmoothed); // Double score4 = div4.getJsdSimScore(); Double FinalScore1 = score1 + (2 * score3); ParsimoniousLM PLM = new ParsimoniousLM(PM_PLMsmoothed, NM_PLMsmoothed); SmoothedLM PLM_smoothed = new SmoothedLM(PLM, CLM); Divergence div1_ = new Divergence(candidateSLM_smoothed, PLM_smoothed); Double score1_ = div1_.getJsdSimScore(); ParsimoniousLM PTM = new ParsimoniousLM(PT_PLMsmoothed, NT_PLMsmoothed); SmoothedLM PTM_smoothed = new SmoothedLM(PTM, CLM); Divergence div2_ = new Divergence(candidateSLM_smoothed, PTM_smoothed); Double score2_ = div2_.getJsdSimScore(); Double FinalScore2 = score1_ + 2 * score2_; // Divergence div1 = new Divergence(candidateSLM, user.userPositiveMixturePLM); // Double score1 = div1.getJsdSimScore(); // Divergence div2 = new Divergence(candidateSLM, user.userNegativeMixturePLM); // Double score2 = div2.getJsdSimScore(); // Divergence div3 = new Divergence(candidateSLM, user.userPositiveMixtureTags); // Double score3 = div3.getJsdSimScore(); // Divergence div4 = new Divergence(candidateSLM, user.userNegativeMixtureTags); // Double score4 = div4.getJsdSimScore(); // Double FinalScore = score1 - score2 + 2 * (score3 - score4); // ParsimoniousLM PLM = new ParsimoniousLM(user.userPositiveMixturePLM, user.userNegativeMixturePLM); // Divergence div1 = new Divergence(candidateSLM, PLM); // Double score1 = div1.getJsdSimScore(); // ParsimoniousLM PTM = new ParsimoniousLM(user.userPositiveMixtureTags, user.userNegativeMixtureTags); // Divergence div2 = new Divergence(candidateSLM, PTM); // Double score2 = div2.getJsdSimScore(); // Double FinalScore = score1 + 2* score2; scores1.put(candidate, FinalScore1); scores2.put(candidate, FinalScore2); } List<Map.Entry<String, Double>> sortedCandidates1 = sortByValues(scores1, false); List<Map.Entry<String, Double>> sortedCandidates2 = sortByValues(scores2, false); System.out.println("Request: " + cnt++ + " - " + user.reqId); // System.out.println(sortedCandidates.toString()); this.OutputGenerator(user.reqId, sortedCandidates1, "response_P.json"); this.OutputGenerator(user.reqId, sortedCandidates2, "response_PLM.json"); // this.OutputGenerator_trecEval(user.reqId, sortedCandidates); } }
From source file:org.crosswalk.eclipse.cdt.newProject.NewPackagedWizard.java
@Override public boolean performFinish() { try {// w ww . java2s. co m // create the web staff here // ---- create the nProject in workspace ---- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); nProject = root.getProject(nProjectWizardState.projectName); nProject.create(null); nProject.open(IResource.BACKGROUND_REFRESH, null); //create the folder for generate app by using crosswalk-app tool.It's under the project folder,and hidden. StringBuilder cmd = new StringBuilder(); String tmpCreateLocation = nProject.getLocation().toString(); File tmpFolder = new File(tmpCreateLocation); cmd.append("mkdir ").append(".tmp"); final Map<String, String> env = new HashMap<String, String>(System.getenv()); Process process = Runtime.getRuntime().exec(cmd.toString(), mapToStringArray(env), tmpFolder); process.waitFor(); ProjectHelper projectHelper = new ProjectHelper(); projectHelper.resourceHandler(tmpCreateLocation + File.separator + ".tmp"); //generate the app in a hidden folder named ".tmp" by using crosswalk-app tool. //copy the generated files into workspace String packageName = CdtConstants.CROSSWALK_PACKAGE_PREFIX + nProjectWizardState.applicationName; String resourceFolder = tmpCreateLocation + File.separator + ".tmp" + File.separator + packageName + File.separator + "app"; Path sourceManifestFile = FileSystems.getDefault().getPath(resourceFolder, "manifest.json"); //copy manifest.json file Path targetManifestFile = FileSystems.getDefault().getPath(nProject.getLocation().toString(), "manifest.json"); Files.copy(sourceManifestFile, targetManifestFile, REPLACE_EXISTING); String manifestLocation = targetManifestFile.toString(); //get the manifest file JSONObject manifest = new JSONObject(new JSONTokener(new FileReader(manifestLocation))); String applicationName = nProjectWizardState.applicationName; //start to modify manifest String iconSize = nProjectWizardState.iconSize; JSONArray icons = manifest.getJSONArray("icons"); manifest.put("name", applicationName); manifest.put("xwalk_version", nProjectWizardState.xwalkVersion); if (!nProjectWizardState.iconPathChanged || nProjectWizardState.useDefaultIcon) {//copy the default icon for app if using default icon. Path sourceIconFile = FileSystems.getDefault().getPath(resourceFolder, "icon-48.png"); Path targetIconFile = FileSystems.getDefault().getPath(nProject.getLocation().toString(), "icon-48.png"); Path sourceIconFile2 = FileSystems.getDefault().getPath(resourceFolder, "icon.png"); Path targetIconFile2 = FileSystems.getDefault().getPath(nProject.getLocation().toString(), "icon.png"); Files.copy(sourceIconFile, targetIconFile, REPLACE_EXISTING); Files.copy(sourceIconFile2, targetIconFile2, REPLACE_EXISTING); } else if (nProjectWizardState.iconPathChanged && !nProjectWizardState.useDefaultIcon) { //copy the specified icon by user into workspace. iconName = nProjectWizardState.favIcon.substring(nProjectWizardState.favIcon.lastIndexOf('/') + 1); Path userIconPath = FileSystems.getDefault().getPath(nProjectWizardState.favIcon); Path targetIconPath = FileSystems.getDefault().getPath(nProject.getLocation().toString(), iconName); Files.copy(userIconPath, targetIconPath, REPLACE_EXISTING); JSONObject newIcon = new JSONObject(); //add the info of user icon into manifest.json for (int i = 0; i < 4; i++) { newIcon.put("src", iconName); newIcon.put("sizes", iconSize); newIcon.put("type", "image/png"); newIcon.put("density", "1.0"); } icons.put(newIcon); } if (nProjectWizardState.startUrlChanged) { //update the start_url domain in manifest.json startUrl = nProjectWizardState.startUrl .substring(nProjectWizardState.startUrl.lastIndexOf("/") + 1); Path sourceStartUrlFile = FileSystems.getDefault().getPath(nProjectWizardState.startUrl); Path targetStartUrlFile = FileSystems.getDefault().getPath(nProject.getLocation().toString(), startUrl); Files.copy(sourceStartUrlFile, targetStartUrlFile); manifest.put("start_url", startUrl); } else { //use default index.html file Path sourceIndexFile = FileSystems.getDefault().getPath(resourceFolder, "index.html"); Path targetIndexFile = FileSystems.getDefault().getPath(nProject.getLocation().toString(), "index.html"); Files.copy(sourceIndexFile, targetIndexFile, REPLACE_EXISTING); } PrintWriter out = new PrintWriter( new FileOutputStream(nProject.getLocation().toFile() + File.separator + "manifest.json")); out.write(manifest.toString(4)); out.close(); // add crosswalk nature to the nProject CrosswalkNature.setupProjectNatures(nProject, null); } catch (Exception e) { CdtPluginLog.logError(e); return false; } return true; }
From source file:com.twosigma.beaker.scala.util.ScalaEvaluator.java
public void initialize(String id, String sId) { logger.debug("id: {}, sId: {}", id, sId); shellId = id;/*from ww w . jav a 2 s . c o m*/ sessionId = sId; classPath = new ArrayList<String>(); imports = new ArrayList<String>(); exit = false; updateLoader = false; currentClassPath = ""; currentImports = ""; outDir = FileSystems.getDefault().getPath(System.getenv("beaker_tmp_dir"), "dynclasses", sessionId) .toString(); try { (new File(outDir)).mkdirs(); } catch (Exception e) { } startWorker(); }
From source file:com.awcoleman.ExampleJobSummaryLogWithOutput.BinRecToAvroRecDriver.java
private boolean copyTempFileAppenderToHDFSOutpath(Job job, String fapath, String outpath) { String sep = FileSystems.getDefault().getSeparator(); try {/*from ww w. j a v a2s. c om*/ FileSystem hdfs = FileSystem.get(job.getConfiguration()); Path localfile = new Path("file://" + fapath); Path hdfsfile = new Path(outpath + sep + "_log" + sep + "joblog.log"); //About to move job summary log to HDFS, so remove from root logger and close FileAppender fa = (FileAppender) Logger.getRootLogger() .getAppender("TempFileAppender_" + job.getJobName()); Logger.getRootLogger().removeAppender(fa); fa.close(); hdfs.copyFromLocalFile(true, false, localfile, hdfsfile); return true; } catch (IOException ioe) { logger.warn("Unable to move job summary log to HDFS.", ioe); return false; } }
From source file:com.twosigma.beaker.groovy.utils.GroovyEvaluator.java
public GroovyEvaluator(String id, String sId) { shellId = id;/* w w w. j ava 2s .com*/ sessionId = sId; cps = new GroovyClasspathScanner(); gac = createGroovyAutocomplete(cps); classPath = new ArrayList<String>(); imports = new ArrayList<String>(); exit = false; updateLoader = false; currentClassPath = ""; currentImports = ""; outDir = FileSystems.getDefault().getPath(System.getenv("beaker_tmp_dir"), "dynclasses", sessionId) .toString(); outDir = envVariablesFilter(outDir, System.getenv()); outDirInput = outDir; try { (new File(outDir)).mkdirs(); } catch (Exception e) { } executor = new BeakerCellExecutor("groovy"); startWorker(); }
From source file:com.acmutv.ontoqa.core.knowledge.KnowledgeManager.java
/** * Writes an ontology on a resource.//from ww w . j a v a2 s . c om * @param resource the resource to write on. * @param ontology the ontology to write. * @param format the ontology format. * @throws IOException when ontology cannot be written. */ public static void write(String resource, Ontology ontology, OntologyFormat format) throws IOException { LOGGER.trace("resource={} ontology={} format={}", resource, ontology, format); Path path = FileSystems.getDefault().getPath(resource).toAbsolutePath(); try (OutputStream out = Files.newOutputStream(path)) { Rio.write(ontology, out, format.getFormat()); } }
From source file:io.mangoo.maven.MangooMojo.java
@Override public void execute() throws MojoExecutionException { if (skip) {/* ww w. j a v a 2 s . c o m*/ getLog().info("Skip flag is on. Will not execute."); return; } initMojo(); checkClasses(buildOutputDirectory); MinificationUtils.setBasePath(project.getBasedir().getAbsolutePath()); List<String> classpathItems = new ArrayList<>(); classpathItems.add(buildOutputDirectory); for (Artifact artifact : project.getArtifacts()) { classpathItems.add(artifact.getFile().toString()); } Set<String> includesSet = new LinkedHashSet<>(includes); Set<String> excludesSet = new LinkedHashSet<>(excludes); Set<Path> watchDirectories = new LinkedHashSet<>(); FileSystem fileSystem = FileSystems.getDefault(); watchDirectories.add(fileSystem.getPath(buildOutputDirectory).toAbsolutePath()); if (this.watchDirs != null) { for (File watchDir : this.watchDirs) { watchDirectories.add(watchDir.toPath().toAbsolutePath()); } } getArtifacts(includesSet, excludesSet, watchDirectories); startRunner(classpathItems, includesSet, excludesSet, watchDirectories); IOUtils.closeQuietly(fileSystem); }