Example usage for java.nio.file FileSystems getDefault

List of usage examples for java.nio.file FileSystems getDefault

Introduction

In this page you can find the example usage for java.nio.file FileSystems getDefault.

Prototype

public static FileSystem getDefault() 

Source Link

Document

Returns the default FileSystem .

Usage

From source file:nl.uva.contextualsuggestion.Ranker_2014.java

public void main() throws FileNotFoundException, IOException {
    File f = new File("response_2014.json");
    f.delete();//from w ww.  j  ava2  s . co m
    File f2 = new File("response-treceval_2014.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);
    Integer cnt = 1;
    this.loadTests();
    this.loadTrain();
    CollectionSLM CLM = new CollectionSLM(ireader, field);
    for (Entry<String, HashMap<String, HashSet<String>>> e : this.test_user_city_suggestions.entrySet()) {
        for (Entry<String, HashSet<String>> e1 : e.getValue().entrySet()) {
            String reqId = e.getKey() + "," + e1.getKey();
            String userId = e.getKey();
            HashSet<Prefrence> pres = new HashSet<>();
            System.out.println(e1.getKey());
            for (Entry<String, Double> e3 : train_user_suggestions_rate.get(e.getKey()).entrySet()) {
                Prefrence p = new Prefrence(e3.getKey(), e3.getValue());
                pres.add(p);
            }
            User user = new User(reqId, userId, pres, e1.getValue());

            HashMap<String, Double> scores = 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);
                //                    Divergence div1 = new Divergence(candidateSLM_smoothed, PM_PLMsmoothed);
                //                    Double score1 = div1.getJsdSimScore();
                Divergence div2 = new Divergence(candidateSLM_smoothed, NM_PLMsmoothed);
                Double score2 = div2.getJsdSimScore();

                //                    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 PLM = new ParsimoniousLM(user.userPositiveMixturePLM, user.userNegativeMixturePLM);
                //                    Divergence div1 = new Divergence(candidateSLM, PLM);
                //                    Double score1 = div1.getJsdSimScore();

                //                    Divergence div1 = new Divergence(candidateSLM, user.userPositiveMixturePLM);
                //                    Double score1 = div1.getJsdSimScore();
                //                    Divergence div2 = new Divergence(candidateSLM, user.userNegativeMixturePLM);
                //                    Double score2 = div2.getJsdSimScore();
                Double FinalScore = -1 * score2;
                scores.put(candidate, FinalScore);
            }
            List<Map.Entry<String, Double>> sortedCandidates = sortByValues(scores, false);
            System.out.println("Request: " + cnt++ + " - " + user.reqId);
            //            System.out.println(sortedCandidates.toString());
            //                this.OutputGenerator(user.reqId, sortedCandidates);
            this.OutputGenerator_trecEval(user.reqId, sortedCandidates);

        }
    }

}

From source file:cz.muni.fi.mir.services.MathCanonicalizerLoaderImpl.java

@Override
public void execute(List<Formula> formulas, ApplicationRun applicationRun) throws IllegalStateException {
    if (!fileService.canonicalizerExists(applicationRun.getRevision().getRevisionHash())) {
        throw new IllegalStateException("Given canonicalizer with revision ["
                + applicationRun.getRevision().getRevisionHash() + "] does not exists.");
    } else {//from  www  .j a  va2 s .com
        Path path = FileSystems.getDefault().getPath(this.jarFolder,
                applicationRun.getRevision().getRevisionHash() + ".jar");
        Class mainClass = null;
        URL jarFile = null;
        try {
            jarFile = path.toUri().toURL();
        } catch (MalformedURLException me) {
            logger.fatal(me);
        }
        URLClassLoader cl = URLClassLoader.newInstance(new URL[] { jarFile });

        try {
            mainClass = cl.loadClass("cz.muni.fi.mir.mathmlcanonicalization." + this.mainClassName);
        } catch (ClassNotFoundException cnfe) {
            logger.fatal(cnfe);
        }

        CanonicalizationTask ct = taskFactory.createTask();

        ct.setDependencies(formulas, applicationRun, mainClass);

        taskService.submitTask(ct);
    }
}

From source file:com.gwac.job.FileTransferServiceImpl.java

public void transFile() {
    System.out.println("123");
    try {/*w  w w .  j a  va  2 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();
    }

    if (isBeiJingServer || !isSuccess) {
        return;
    }

    if (running == true) {
        log.debug("start job fileTransferJob...");
        running = false;
    } else {
        log.warn("job fileTransferJob is running, jump this scheduler.");
        return;
    }
    try {
        WatchKey key = watcher.poll();
        if (key != null) {
            for (WatchEvent<?> event : key.pollEvents()) {
                WatchEvent.Kind<?> kind = event.kind();
                WatchEvent<Path> ev = (WatchEvent<Path>) event;
                Path fileName = ev.context();
                System.out.println(kind.name() + ": " + fileName);

                if (kind == ENTRY_MODIFY) {
                    System.out.println("My source file has changed!!!");
                }
            }
        }

        boolean valid = key.reset();
        if (!valid) {
            return;
        }
    } catch (Exception ex) {
    }

    if (running == false) {
        running = true;
        log.debug("job fileTransferJob is done.");
    }
}

From source file:im.bci.gamesitekit.GameSiteKitMain.java

public boolean init(String[] args) throws IOException {
    CmdLineParser parser = new CmdLineParser(this);
    try {//  w  w w  .  j ava 2 s .  c  om
        parser.parseArgument(args);
        if (null == inputDir) {
            inputDir = FileSystems.getDefault().getPath("games/newtonadventure");
        }
        if (null == templateDir) {
            templateDir = FileSystems.getDefault().getPath("template");
        }
        if (null == outputDir) {
            outputDir = FileSystems.getDefault().getPath("target/site");
        }
        screenshotsOutputDir = outputDir.resolve("screenshots");
        screenshotThumbnailsOutputDir = screenshotsOutputDir.resolve("thumbnails");
        screenshotsInputDir = inputDir.resolve("screenshots");
        screenshotThumbnailsInputDir = screenshotsInputDir.resolve("thumbnails");
        styleInputDir = templateDir.resolve("style");
        styleOutputDir = outputDir.resolve("style");
        scriptsInputDir = templateDir.resolve("scripts");
        scriptsOutputDir = outputDir.resolve("scripts");
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        System.err.println("gamesitekit [options...] arguments...");
        parser.printUsage(System.err);
        System.err.println(" Example: gamesitekit " + parser.printExample(OptionHandlerFilter.ALL));
        return false;
    }
    initFreemarker();
    return true;
}

From source file:org.ng200.openolympus.services.StorageService.java

@PreAuthorize(SecurityExpressionConstants.IS_ADMIN)
public Path createTaskJudgeDirectory(Task task) throws IOException {
    final UUID uuid = UUID.randomUUID();
    final Path dir = FileSystems.getDefault().getPath(this.storagePath, "tasks", "judges", uuid.toString());
    FileAccess.createDirectories(dir);//  w  w w  . ja v  a2 s .c  o  m
    task.setTaskLocation(uuid.toString());
    return dir;
}

From source file:com.awcoleman.ExampleJobSummaryLogWithOutput.BinRecToAvroRecDriver.java

private String createTempFileAppender(Job job) throws IOException {
    String sep = FileSystems.getDefault().getSeparator();

    //JobID may not exist yet, but JobName does since we call getInstance with name, so use JobName as prefix
    java.nio.file.Path temppath = Files.createTempDirectory(job.getJobName() + "_");

    String fapath = temppath + sep + "joblog.log";

    FileAppender fa = new FileAppender();
    fa.setName("TempFileAppender_" + job.getJobName());
    fa.setFile(fapath);//from w ww  . j  ava 2s.  co m
    fa.setLayout(new PatternLayout("%d{ISO8601} %p %c: %m%n"));
    fa.setThreshold(Level.INFO);
    fa.setAppend(true);
    fa.activateOptions();

    Logger.getRootLogger().addAppender(fa);

    //Add cleanup hooks, log file itself should be deleted by copyFromLocalFile after copy to HDFS
    temppath.toFile().deleteOnExit();

    return fapath;
}

From source file:jvmoptions.OptionAnalyzer.java

static Map<String, Map<String, String>> makeMap(String root) throws Exception {
    Path start = FileSystems.getDefault().getPath(root);
    File dir = start.toFile();/*from  w  w  w.  j a  v  a  2 s  . c  o m*/
    if (dir.exists() == false || dir.isDirectory() == false) {
        System.err.printf("%s doesn't exists or doesn't dir %n", root);
        System.err.println("run gradle task below");
        System.err.println("gradlew getSrcs");
        System.exit(1);
    }

    return Files.walk(start).map(Path::toFile).filter(File::isFile).filter(f -> f.getName().endsWith(".hpp"))
            .map(File::toPath).parallel().filter(OptionAnalyzer::contains).map(OptionAnalyzer::parse)
            .map(Map::entrySet).flatMap(Collection::stream)
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, OptionAnalyzer::merge));
}

From source file:org.apache.nifi.minifi.bootstrap.configuration.ingestors.FileChangeIngestor.java

protected static WatchService initializeWatcher(Path filePath) {
    try {//from ww w . j  av a  2s .co m
        final WatchService fsWatcher = FileSystems.getDefault().newWatchService();
        final Path watchDirectory = filePath.getParent();
        watchDirectory.register(fsWatcher, ENTRY_MODIFY);

        return fsWatcher;
    } catch (IOException ioe) {
        throw new IllegalStateException("Unable to initialize a file system watcher for the path " + filePath,
                ioe);
    }
}

From source file:org.cryptomator.ui.logging.ConfigurableFileAppender.java

private static Path parsePath(String path) {
    if (path.startsWith("~/")) {
        // home-dir-relative Path:
        final Path userHome = FileSystems.getDefault().getPath(SystemUtils.USER_HOME);
        return userHome.resolve(path.substring(2));
    } else if (path.startsWith("/")) {
        // absolute Path:
        return FileSystems.getDefault().getPath(path);
    } else {//  w w  w.j  a  v  a2  s.  c  om
        // relative Path:
        try {
            String jarFileLocation = ConfigurableFileAppender.class.getProtectionDomain().getCodeSource()
                    .getLocation().toURI().getPath();
            if (SystemUtils.IS_OS_WINDOWS
                    && DRIVE_LETTER_WITH_PRECEEDING_SLASH.matcher(jarFileLocation).find()) {
                // on windows we need to remove a preceeding slash from "/C:/foo/bar":
                jarFileLocation = jarFileLocation.substring(1);
            }
            final Path workingDir = FileSystems.getDefault().getPath(jarFileLocation).getParent();
            return workingDir.resolve(path);
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to resolve working directory ", e);
            return null;
        }
    }
}

From source file:org.cryptomator.webdav.jackrabbit.DavLocatorFactoryImpl.java

private String encryptRepositoryPath(String resourcePath) {
    if (resourcePath == null) {
        return fsRoot.toString();
    }/*ww w .  jav  a 2s  .  c o m*/
    final String encryptedRepoPath = cryptor.encryptPath(resourcePath,
            FileSystems.getDefault().getSeparator().charAt(0), '/', this);
    return fsRoot.resolve(encryptedRepoPath).toString();
}