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:org.xlrnet.tibaija.tools.fontgen.FontgenApplication.java

@NotNull
private Font importFont(String source, String fontIdentifier) throws IOException {
    Path sourcePath = Paths.get(source);

    Pattern filePattern = Pattern.compile("[0-9A-F]{2}h_" + fontIdentifier + "[a-zA-Z0-9]*.gif");

    List<Path> fileList = Files.list(sourcePath)
            .filter(p -> filePattern.matcher(p.getFileName().toString()).matches())
            .collect(Collectors.toList());

    Font font = new Font();
    List<Symbol> symbols = new ArrayList<>();

    for (Path path : fileList) {
        try {/*  www.  ja  v  a  2  s.c o  m*/
            Symbol symbol = importFile(path, font, fontIdentifier);

            if (symbol == null)
                continue;

            String filename = path.getFileName().toString();
            String hexValue = StringUtils.substring(filename, 0, 2);
            String internalIdentifier = StringUtils.substringBetween(filename, "_" + fontIdentifier, ".gif");

            symbol.setHexValue(hexValue);
            symbol.setInternalIdentifier(internalIdentifier);

            symbols.add(symbol);
        } catch (ImageReadException e) {
            LOGGER.error("Reading image {} failed", path.toAbsolutePath(), e);
        }
    }

    Collections.sort(symbols);
    font.setSymbols(symbols);

    return font;
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup.java

private String pathToURI(Path path, String type) {
    return FILEGRAPH_URI_ROOT + type + "/" + path.getFileName();
}

From source file:org.sonarlint.intellij.core.SonarLintServerManager.java

private URL[] loadPlugins() throws IOException, URISyntaxException {
    URL pluginsDir = this.getClass().getClassLoader().getResource("plugins");

    if (pluginsDir == null) {
        throw new IllegalStateException("Couldn't find plugins");
    }/* ww  w .  j a v  a2s. c  o m*/

    List<URL> pluginsUrls = new ArrayList<>();
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(pluginsDir.toURI()),
            "*.jar")) {
        for (Path path : directoryStream) {
            globalLogOutput.log("Found plugin: " + path.getFileName().toString(), LogOutput.Level.DEBUG);
            pluginsUrls.add(path.toUri().toURL());
        }
    }
    return pluginsUrls.toArray(new URL[pluginsUrls.size()]);
}

From source file:de.tiqsolutions.hdfs.HadoopFileSystemPath.java

Deque<Path> getPathSegments() {
    Deque<Path> paths = new ArrayDeque<>();
    Path root = getRoot();/*  w ww.  jav a  2  s.  c om*/
    Path p = this;
    while (p != null && !p.equals(root)) {
        paths.push(p.getFileName());
        p = p.getParent();
    }
    return paths;
}

From source file:FTP.FileUploading.java

private String getWithoutExtention(String File) {
    Path F = Paths.get(File, "");
    String fname = F.getFileName().toString();
    int pos = fname.lastIndexOf(".");
    if (pos > 0) {
        fname = fname.substring(0, pos);
    }//from  www  .j av  a2s.  c o m
    return fname;
}

From source file:de.thomasbolz.renamer.Renamer.java

/**
 * Step 1 of the renaming process:/*w  w w. j av  a2 s .c o  m*/
 * Analysis steps in the renaming process. Walks the whole file tree of the source directory and creates a CopyTask
 * for each file or directory that is found and does not match the exclusion list.
 * @return a list of all CopyTasks
 */
public Map<Path, List<CopyTask>> prepareCopyTasks() {

    try {
        Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {

                    /**
                     * If we find a directory create/copy it and add a counter
                     *
                     * @param dir
                     * @param attrs
                     * @return
                     * @throws java.io.IOException
                     */
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                            throws IOException {
                        Path targetdir = target.resolve(source.relativize(dir));
                        copyTasks.put(dir, new ArrayList<CopyTask>());
                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        if (!file.getFileName().toString().toLowerCase().matches(EXLUSION_REGEX)) {
                            copyTasks.get(file.getParent()).add(new CopyTask(file, null));
                        } else {
                            excludedFiles.add(file);
                        }
                        return FileVisitResult.CONTINUE;
                    }
                });
    } catch (IOException e) {
        e.printStackTrace();
    }
    sortCopyTasks();
    //        generateTargetFilenames();
    return copyTasks;
}

From source file:de.dentrassi.rpm.builder.YumMojo.java

private void addSinglePackage(final Path path, final Context context) throws IOException {
    final String checksum = makeChecksum(path);
    final String fileName = path.getFileName().toString();
    final String location = "packages/" + fileName;
    final FileInformation fileInformation = new FileInformation(Files.getLastModifiedTime(path).toInstant(),
            Files.size(path), location);

    final RpmInformation rpmInformation;
    try (RpmInputStream ris = new RpmInputStream(Files.newInputStream(path))) {
        rpmInformation = RpmInformations.makeInformation(ris);
    }/*from  w  ww  . j av a 2s . c  o  m*/

    context.addPackage(fileInformation, rpmInformation, singletonMap(SHA256, checksum), SHA256);

    Files.copy(path, this.packagesPath.toPath().resolve(fileName), StandardCopyOption.COPY_ATTRIBUTES);
}

From source file:it.greenvulcano.configuration.BaseConfigurationManager.java

@Override
public String getCurrentConfigurationName() {
    Path current = Paths.get(XMLConfig.getBaseConfigPath());

    return current.getFileName().toString();
}

From source file:net.fatlenny.datacitation.service.GitCitationDBService.java

@Override
public List<String> getDatasetNames() throws CitationDBException {
    checkoutBranch(REF_MASTER);//  w  w  w  . j  a  v  a 2 s  .  co  m

    List<String> databaseFileNames = new ArrayList<>();
    String workingTreeDir = getWorkingTreeDir();

    try (DirectoryStream<Path> ds = Files.newDirectoryStream(Paths.get(workingTreeDir), "*." + CSV_ENDING)) {
        for (Path path : ds) {
            String pathName = path.getFileName().toString();
            databaseFileNames.add(pathName.substring(0, pathName.lastIndexOf(".")));
        }
    } catch (IOException e) {
        throw new CitationDBException("Error reading data files: ", e);
    }

    return databaseFileNames;
}

From source file:at.ac.univie.isc.asio.platform.FileSystemConfigStore.java

@Override
public Map<String, ByteSource> findAllWithIdentifier(final String identifier) throws DataAccessException {
    final FindFiles collector = FindFiles.filter(filesWithIdentifier(identifier));
    Map<String, ByteSource> found = new HashMap<>();
    try {//  ww w. j  av a  2s.  c  o m
        log.debug(Scope.SYSTEM.marker(), "searching items with identifier <{}>", identifier);
        lock();
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), 1, collector);
        for (final Path path : collector.found()) {
            log.debug(Scope.SYSTEM.marker(), "found <{}>", path);
            final Path fileName = path.getFileName();
            final String[] parts = fileName.toString().split("\\#\\#");
            found.put(parts[0], asByteSource(path.toFile()));
        }
    } catch (IOException e) {
        throw new FileSystemAccessFailure("finding items of type <" + identifier + "> failed", e);
    } finally {
        lock.unlock();
    }
    return ImmutableMap.copyOf(found);
}