Example usage for java.nio.file Path getFileName

List of usage examples for java.nio.file Path getFileName

Introduction

In this page you can find the example usage for java.nio.file Path getFileName.

Prototype

Path getFileName();

Source Link

Document

Returns the name of the file or directory denoted by this path as a Path object.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.actions.Explode.java

private void extract(ActionDescription aAction, Path aArchive, ArchiveInputStream aAStream, Path aTarget)
        throws IOException {
    // We always extract archives into a subfolder. Figure out the name of the folder.
    String base = getBase(aArchive.getFileName().toString());

    Map<String, Object> cfg = aAction.getConfiguration();
    int strip = cfg.containsKey("strip") ? (int) cfg.get("strip") : 0;

    AntFileFilter filter = new AntFileFilter(coerceToList(cfg.get("includes")),
            coerceToList(cfg.get("excludes")));

    ArchiveEntry entry = null;//  ww  w  .j a v a2s .  c om
    while ((entry = aAStream.getNextEntry()) != null) {
        String name = stripLeadingFolders(entry.getName(), strip);

        if (name == null) {
            // Stripped to null - nothing left to extract - continue;
            continue;
        }

        if (filter.accept(name)) {
            Path out = aTarget.resolve(base).resolve(name);
            if (entry.isDirectory()) {
                Files.createDirectories(out);
            } else {
                Files.createDirectories(out.getParent());
                Files.copy(aAStream, out);
            }
        }
    }
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectoryV2.java

private void loadSharedParameters(Path instanceDir, Map<String, SharedParametersV2> sharedParams)
        throws Exception {
    String instanceId = instanceDir.getFileName().toString();

    Path sharedParametersPath = Paths.get(instanceDir.toString(), SHARED_PARAMETERS_XML);
    if (Files.exists(sharedParametersPath)) {
        log.trace("Loading shared parameters from {}", sharedParametersPath);

        sharedParams.put(instanceId, loadParameters(sharedParametersPath, SharedParametersV2.class,
                this.sharedParameters.get(instanceId)));
    } else {//from   ww  w.  ja  va2 s.co  m
        log.trace("Not loading shared parameters from {}, " + "file does not exist", sharedParametersPath);
    }
}

From source file:org.alfresco.repo.bulkimport.impl.DirectoryAnalyserImpl.java

private boolean isVersionFile(Path file) {
    Matcher matcher = VERSION_SUFFIX_PATTERN.matcher(file.getFileName().toString());

    return matcher.matches();
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectoryV1.java

private void loadSharedParameters(Path instanceDir, Map<String, SharedParametersV1> sharedParams)
        throws Exception {
    String instanceId = instanceDir.getFileName().toString();

    Path sharedParametersPath = Paths.get(instanceDir.toString(), SHARED_PARAMETERS_XML);
    if (Files.exists(sharedParametersPath)) {
        log.trace("Loading shared parameters from {}", sharedParametersPath);

        sharedParams.put(instanceId, loadParameters(sharedParametersPath, SharedParametersV1.class,
                this.sharedParameters.get(instanceId)));
    } else {/*  w w  w.  j a va 2 s  . c  o m*/
        log.trace("Not loading shared parameters from {}, " + "file does not exist", sharedParametersPath);
    }
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectoryV2.java

private void loadPrivateParameters(Path instanceDir, Map<String, PrivateParametersV2> privateParams)
        throws Exception {
    String instanceId = instanceDir.getFileName().toString();

    Path privateParametersPath = Paths.get(instanceDir.toString(), PRIVATE_PARAMETERS_XML);

    if (Files.exists(privateParametersPath)) {
        log.trace("Loading private parameters from {}", privateParametersPath);

        privateParams.put(instanceId, loadParameters(privateParametersPath, PrivateParametersV2.class,
                this.privateParameters.get(instanceId)));
    } else {/*from   w ww  . j  a v  a  2 s  .co m*/
        log.trace("Not loading private parameters from {}, " + "file does not exist", privateParametersPath);
    }
}

From source file:com.htmlhifive.visualeditor.persister.LocalFileContentsPersister.java

/**
 * ????./*from  ww  w  .ja v a2  s .c  o  m*/
 * 
 * @param metadata ?urlTree
 * @param ctx urlTree
 */
@Override
public void rmdir(UrlTreeMetaData<InputStream> metadata, UrlTreeContext ctx)
        throws BadContentException, FileNotFoundException {
    Path f = generateFileObj(metadata.getAbsolutePath());
    logger.debug("called rmdir: " + f.getFileName());
    if (!Files.exists(f)) {
        throw new FileNotFoundException("file not exists");
    }

    try {
        Files.delete(f);
    } catch (IOException e) {
        logger.error("rmdir failure", e);
        throw new RuntimeException(e);
    }
}

From source file:com.bekwam.resignator.commands.UnsignCommand.java

private void registerCleanup() {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override//  ww  w  . j  a va 2s  .  com
        public void run() {
            if (logger.isDebugEnabled()) {
                logger.debug("[UNSIGN] shutting down unsign jar command");
            }
            if (tempDir != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("[UNSIGN] tempDir is not null");
                }
                try {
                    Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {
                        @Override
                        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                                throws IOException {
                            if (logger.isDebugEnabled()) {
                                logger.debug("[UNSIGN] deleting file={}", file.getFileName());
                            }
                            Files.delete(file);
                            return FileVisitResult.CONTINUE;
                        }

                        @Override
                        public FileVisitResult postVisitDirectory(Path dir, IOException exc)
                                throws IOException {
                            if (exc == null) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("[UNSIGN] deleting dir={}", dir.getFileName());
                                }
                                Files.delete(dir);
                                return FileVisitResult.CONTINUE;
                            } else {
                                // directory iteration failed
                                throw exc;
                            }
                        }
                    });
                } catch (Exception exc) {
                    logger.error("error removing tempDir=" + tempDir, exc);
                }
            }
        }
    });
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectoryV1.java

private void loadPrivateParameters(Path instanceDir, Map<String, PrivateParametersV1> privateParams)
        throws Exception {
    String instanceId = instanceDir.getFileName().toString();

    Path privateParametersPath = Paths.get(instanceDir.toString(), PRIVATE_PARAMETERS_XML);

    if (Files.exists(privateParametersPath)) {
        log.trace("Loading private parameters from {}", privateParametersPath);

        privateParams.put(instanceId, loadParameters(privateParametersPath, PrivateParametersV1.class,
                this.privateParameters.get(instanceId)));
    } else {/*from  w  w w. j  av  a2s  . co  m*/
        log.trace("Not loading private parameters from {}, " + "file does not exist", privateParametersPath);
    }
}

From source file:com.ejisto.util.visitor.ConditionMatchingCopyFileVisitor.java

private void copy(Path srcFile) throws IOException {
    Path relative = options.srcRoot.relativize(srcFile);
    int count = relative.getNameCount();
    StringBuilder newFileName = new StringBuilder();
    if (count > 1) {
        newFileName.append(relative.getParent().toString());
        newFileName.append(File.separator);
    }/*from ww w .  ja v  a  2 s  . c o  m*/
    newFileName.append(defaultString(options.filesPrefix)).append(srcFile.getFileName().toString());
    Files.copy(srcFile, options.targetRoot.resolve(newFileName.toString()),
            StandardCopyOption.REPLACE_EXISTING);
}

From source file:diffhunter.Indexer.java

public void Make_Index(Database hashdb, String file_name, String read_gene_location)
        throws FileNotFoundException, IOException {
    Set_Parameters();//from  w  w  w .j  ava2 s.  co m
    //System.out.print("Sasa");
    ConcurrentHashMap<String, Map<Integer, Integer>> dic_gene_loc_count = new ConcurrentHashMap<>();
    ArrayList<String> lines_from_bed_file = new ArrayList<>();
    BufferedReader br = new BufferedReader(new FileReader(file_name));

    String line = br.readLine();
    List<String> toks = Arrays.asList(line.split("\t"));
    lines_from_bed_file.add(line);
    String last_Seen_chromosome = toks.get(0).replace("chr", "");
    line = br.readLine();
    lines_from_bed_file.add(line);
    toks = Arrays.asList(line.split("\t"));
    String new_chromosome = toks.get(0).replace("chr", "");

    while (((line = br.readLine()) != null) || lines_from_bed_file.size() > 0) {
        if (line != null) {
            toks = Arrays.asList(line.split("\t"));
            new_chromosome = toks.get(0).replace("chr", "");
        }
        // process the line.
        if (line == null || !new_chromosome.equals(last_Seen_chromosome)) {
            System.out.println("Processing chromosome" + "\t" + last_Seen_chromosome);
            last_Seen_chromosome = new_chromosome;
            lines_from_bed_file.parallelStream().forEach(content -> {

                List<String> inner_toks = Arrays.asList(content.split("\t"));
                //WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING 
                //STRAND column count should be changed. 
                String strand = inner_toks.get(5);
                String chromosome_ = inner_toks.get(0).replace("chr", "");
                if (!dic_Loc_gene.get(strand).containsKey(chromosome_)) {
                    return;
                }
                Integer start_loc = Integer.parseInt(inner_toks.get(1));
                Integer end_loc = Integer.parseInt(inner_toks.get(2));
                List<Interval<String>> res__ = dic_Loc_gene.get(strand).get(chromosome_).getIntervals(start_loc,
                        end_loc);
                //IntervalTree<String> pot_gene_name=new IntervalTree<>(res__);
                //                        for (int z = 0; z < pot_gene_name.Intervals.Count; z++)
                //{
                for (int z = 0; z < res__.size(); z++) {

                    dic_gene_loc_count.putIfAbsent(res__.get(z).getData(), new HashMap<>());
                    String gene_symbol = res__.get(z).getData();
                    Integer temp_gene_start_loc = dic_genes.get(gene_symbol).start_loc;
                    Integer temp_gene_end_loc = dic_genes.get(gene_symbol).end_loc;
                    if (start_loc < temp_gene_start_loc) {
                        start_loc = temp_gene_start_loc;
                    }
                    if (end_loc > temp_gene_end_loc) {
                        end_loc = temp_gene_end_loc;
                    }
                    synchronized (dic_synchrinzer_genes.get(gene_symbol)) {
                        for (int k = start_loc; k <= end_loc; k++) {
                            Integer value_inside = 0;
                            value_inside = dic_gene_loc_count.get(gene_symbol).get(k);
                            dic_gene_loc_count.get(gene_symbol).put(k,
                                    value_inside == null ? 1 : (value_inside + 1));
                        }
                    }
                }
            });
            /*                    List<string> keys_ = dic_gene_loc_count.Keys.ToList();
             List<string> alt_keys = new List<string>();// dic_gene_loc_count.Keys.ToList();
             for (int i = 0; i < keys_.Count; i++)
             {
             Dictionary<int, int> dicccc_ = new Dictionary<int, int>();
             dic_gene_loc_count[keys_[i]] = new Dictionary<int, int>(dic_gene_loc_count[keys_[i]].Where(x => x.Value >= 2).ToDictionary(x => x.Key, x => x.Value));
             if (dic_gene_loc_count[keys_[i]].Count == 0)
             {
                    
             dic_gene_loc_count.TryRemove(keys_[i], out dicccc_);
             continue;
             }
             hashdb.Put(Get_BDB(keys_[i]), Get_BDB_Dictionary(dic_gene_loc_count[keys_[i]]));
             alt_keys.Add(keys_[i]);
             dic_gene_loc_count.TryRemove(keys_[i], out dicccc_);
             }*/
            ArrayList<String> keys_ = new ArrayList<>(dic_gene_loc_count.keySet());
            ArrayList<String> alt_keys = new ArrayList<>();
            for (int i = 0; i < keys_.size(); i++) {

                //LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>(dic_gene_loc_count.get(keys_.get(i)));
                LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>();
                /*tmep_map = */
                dic_gene_loc_count.get(keys_.get(i)).entrySet().stream().filter(p -> p.getValue() >= 2)
                        .sorted(Comparator.comparing(E -> E.getKey()))
                        .forEach((entry) -> tmep_map.put(entry.getKey(), entry.getValue()));//.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
                if (tmep_map.isEmpty()) {
                    dic_gene_loc_count.remove(keys_.get(i));
                    continue;
                }

                //Map<Integer, Integer> tmep_map1 = new LinkedHashMap<>();
                //tmep_map1=sortByKey(tmep_map);
                //tmep_map.entrySet().stream().sorted(Comparator.comparing(E -> E.getKey())).forEach((entry) -> tmep_map1.put(entry.getKey(), entry.getValue()));
                //BerkeleyDB_Box box=new BerkeleyDB_Box();
                hashdb.put(null, BerkeleyDB_Box.Get_BDB(keys_.get(i)),
                        BerkeleyDB_Box.Get_BDB_Dictionary(tmep_map));
                alt_keys.add(keys_.get(i));
                dic_gene_loc_count.remove(keys_.get(i));
                //dic_gene_loc_count.put(keys_.get(i),tmep_map);
            }

            hashdb.sync();
            int a = 1111;
            /*                    hashdb.Sync();
             File.AppendAllLines("InputDB\\" + Path.GetFileNameWithoutExtension(file_name) + "_genes.txt", alt_keys);
             //total_lines_processed_till_now += lines_from_bed_file.Count;
             //worker.ReportProgress(total_lines_processed_till_now / count_);
             lines_from_bed_file.Clear();
             if (!reader.EndOfStream)
             {
             lines_from_bed_file.Add(_line_);
             }
             last_Seen_chromosome = new_choromosome;*/
            lines_from_bed_file.clear();
            if (line != null) {
                lines_from_bed_file.add(line);
            }
            Path p = Paths.get(file_name);
            file_name = p.getFileName().toString();

            BufferedWriter output = new BufferedWriter(new FileWriter((Paths
                    .get(read_gene_location, FilenameUtils.removeExtension(file_name) + ".txt").toString()),
                    true));
            for (String alt_key : alt_keys) {
                output.append(alt_key);
                output.newLine();
            }
            output.close();
            /*if (((line = br.readLine()) != null))
            {
            lines_from_bed_file.add(line);
            toks=Arrays.asList(line.split("\t"));
            new_chromosome=toks.get(0).replace("chr", "");
            }*/
            //last_Seen_chromosome=new_chromosome;
        } else if (new_chromosome.equals(last_Seen_chromosome)) {
            lines_from_bed_file.add(line);
        }

    }
    br.close();
    hashdb.sync();
    hashdb.close();

}