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:com.datastax.loader.CqlDelimLoadTask.java

private void cleanup(boolean success) throws IOException {
    if (null != badParsePrinter) {
        if (format.equalsIgnoreCase("jsonarray"))
            badParsePrinter.println("]");
        badParsePrinter.close();/*from www . j  a  v a 2s  .co  m*/
    }
    if (null != badInsertPrinter) {
        if (format.equalsIgnoreCase("jsonarray"))
            badInsertPrinter.println("]");
        badInsertPrinter.close();
    }
    if (null != logPrinter)
        logPrinter.close();
    if (success) {
        if (null != successDir) {
            Path src = infile.toPath();
            Path dst = Paths.get(successDir);
            Files.move(src, dst.resolve(src.getFileName()), StandardCopyOption.REPLACE_EXISTING);
        }
    } else {
        if (null != failureDir) {
            Path src = infile.toPath();
            Path dst = Paths.get(failureDir);
            Files.move(src, dst.resolve(src.getFileName()), StandardCopyOption.REPLACE_EXISTING);
        }
    }
}

From source file:com.facebook.buck.util.ProjectFilesystemTest.java

@Test
public void testWalkFileTreeWhenProjectRootIsWorkingDir() throws IOException {
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get("."));
    final ImmutableList.Builder<String> fileNames = ImmutableList.builder();

    Path pathRelativeToProjectRoot = Paths.get("test/com/facebook/buck/util/testdata");
    projectFilesystem.walkRelativeFileTree(pathRelativeToProjectRoot, new SimpleFileVisitor<Path>() {
        @Override/*  w  ww. ja v a 2  s.c  o m*/
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
            fileNames.add(file.getFileName().toString());
            return FileVisitResult.CONTINUE;
        }
    });

    assertThat(fileNames.build(), containsInAnyOrder("file", "a_file", "b_file", "b_c_file", "b_d_file"));
}

From source file:edu.chalmers.dat076.moviefinder.service.MovieFileDatabaseHandlerImpl.java

@Override
public void saveFile(final Path path) {
    Runnable r = new Runnable() {

        @Override//from  w w w  .j a v  a 2  s . co  m
        @Transactional
        public void run() {
            try {
                TemporaryMedia temporaryMedia = new TitleParser().parseMedia(path.getFileName().toString());
                TraktResponse traktData = new TraktHandler().getByTmpMedia(temporaryMedia);
                if (traktData != null) {
                    if (traktData instanceof TraktMovieResponse) {
                        Movie movie = new Movie(path.toString(), traktData);
                        try {
                            try {
                                movieSemaphore.acquire();
                            } catch (InterruptedException ex) {
                            }
                            movieRepository.save(movie);
                        } catch (DataIntegrityViolationException e) {
                        } finally {
                            movieSemaphore.release();
                        }
                    } else {
                        TraktEpisodeResponse epr = (TraktEpisodeResponse) traktData;
                        Semaphore sLock = serieLock.get(epr.getShow().getTitle());
                        if (sLock == null) {
                            sLock = new Semaphore(1, true);
                            serieLock.put(epr.getShow().getTitle(), sLock);
                        }
                        try {
                            sLock.acquire();
                            Series s = seriesRepository.findByImdbId(epr.getShow().getImdbId());
                            if (s == null) {
                                TraktShowResponse sr = new TraktHandler()
                                        .getByShowName(temporaryMedia.getName());
                                if (sr != null) {
                                    s = new Series(sr);
                                    seriesRepository.save(s);
                                }
                            }

                            if (s != null) {
                                Episode ep = new Episode(path.toString(), traktData, s);
                                episodeRepository.save(ep);
                            }
                        } catch (InterruptedException ex) {
                        } finally {
                            sLock.release();
                        }

                    }
                }
            } finally {
                lock.release();
            }
        }

    };

    try {
        lock.acquire();
    } catch (InterruptedException ex) {
    }

    new Thread(r).start();
}

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

private boolean isMetadataFile(Path file) {
    boolean result = false;

    if (metadataLoader != null) {
        String name = file.getFileName().toString();
        result = name.endsWith(MetadataLoader.METADATA_SUFFIX + metadataLoader.getMetadataFileExtension());
    }//from   www. j a  v a2  s . com

    return (result);
}

From source file:dk.dma.ais.utils.filter.AisFilter.java

private PrintStream getNextOutputStram() {
    if (outFile == null) {
        throw new Error("No output stream and no out file argument given");
    }/*  www  .ja va 2  s. c o m*/
    String filename;
    if (splitSize == null) {
        filename = outFile;
    } else {
        Path path = Paths.get(outFile);
        filename = String.format("%06d", fileCounter++) + "." + path.getFileName();
        Path dir = path.getParent();
        if (dir != null) {
            filename = dir + "/" + filename;
        }
    }
    if (compress) {
        filename += ".gz";
    }
    try {
        if (!compress) {
            return new PrintStream(filename);
        } else {
            return new PrintStream(new GZIPOutputStream(new FileOutputStream(filename)));
        }
    } catch (IOException e) {
        throw new RuntimeException("Failed to open output file: " + filename, e);
    }
}

From source file:ca.phon.plugins.praat.TextGridManager.java

/**
 * List available TextGrids for a given session.
 * /*w ww.  ja  v a 2s.c o  m*/
 * @param corpus
 * @param session
 * 
 * @return list of TextGrid files available
 */
public List<File> textGridFilesForSession(String corpus, String session) {
    List<File> retVal = new ArrayList<>();

    final Path textGridFolderPath = Paths.get(textGridFolder(corpus, session));
    if (Files.exists(textGridFolderPath)) {
        try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(textGridFolderPath)) {
            for (Path subFile : directoryStream) {
                if (subFile.getFileName().toString().endsWith(TEXTGRID_EXT)) {
                    retVal.add(subFile.toFile());
                }
            }
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    }

    return retVal;
}

From source file:com.fizzed.blaze.ssh.SshIntegrationTest.java

@Test
public void sftpPutTwiceOverwrites() throws Exception {
    Path exampleFile = FileHelper.resourceAsPath("/example/test1.txt");

    try (SshSession ssh = sshConnect(uri).configFile(sshConfigFile).run()) {
        try (SshSftpSession sftp = SecureShells.sshSftp(ssh).run()) {
            // make sure file does not exist on remote system
            sshExec(ssh, "rm", "-f", "test1.txt").run();

            sftp.put().source(exampleFile).target(exampleFile.getFileName()).run();

            sftp.put().source(exampleFile).target(exampleFile.getFileName()).run();
        }//w  w  w .  j a v a  2s. c  o  m
    }
}

From source file:com.sastix.cms.server.services.content.impl.ZipHandlerServiceImpl.java

public String findStartPage(final Path metadataPath) {
    final String json;
    try {//from   w w  w.jav a2 s .c  o  m
        json = new String(Files.readAllBytes(metadataPath), "UTF-8");
    } catch (IOException e) {
        LOG.error("Error in determining if it is a cms zip resource: {}", e.getLocalizedMessage());
        throw new ResourceAccessError("Zip " + metadataPath.getFileName() + " cannot be read. ");
    }

    final Map<String, Object> map = gsonJsonParser.parseMap(json);

    String startPage;
    if (map.get(METADATA_STARTPAGE) != null) {
        startPage = (String) map.get(METADATA_STARTPAGE);
    } else if (map.get(METADATA_STARTPAGE_CAMEL) != null) {
        startPage = (String) map.get(METADATA_STARTPAGE_CAMEL);
    } else {
        throw new ResourceAccessError("Start page in Zip " + metadataPath.getFileName() + " cannot be found");
    }

    return startPage;
}

From source file:com.fizzed.blaze.ssh.SshIntegrationTest.java

@Test
public void sftpPutAndGet() throws Exception {
    Path exampleFile = FileHelper.resourceAsPath("/example/test1.txt");

    try (SshSession ssh = sshConnect(uri).configFile(sshConfigFile).run()) {
        try (SshSftpSession sftp = SecureShells.sshSftp(ssh).run()) {
            // make sure file does not exist on remote system
            sshExec(ssh, "rm", "-f", "test1.txt").run();

            sftp.put().source(exampleFile).target(exampleFile.getFileName()).run();

            File tempFile = File.createTempFile("blaze.", ".sshtest");
            tempFile.deleteOnExit();// w w w  . j  av a  2 s .com

            sftp.get().source(exampleFile.getFileName()).target(tempFile).run();

            // files match?
            assertTrue("The files differ!", FileUtils.contentEquals(tempFile, exampleFile.toFile()));
        }
    }
}

From source file:com.facebook.buck.java.JarDirectoryStepTest.java

@Test
public void shouldFailIfMainClassMissing() throws IOException {
    Path zipup = folder.newFolder("zipup");

    Path zip = createZip(zipup.resolve("a.zip"), "com/example/Main.class");

    JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(zipup), Paths.get("output.jar"),
            ImmutableSet.of(zip.getFileName()), "com.example.MissingMain", /* manifest file */ null);
    TestConsole console = new TestConsole();
    ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).build();

    int returnCode = step.execute(context);

    assertEquals(1, returnCode);//  w w w.j a  v  a  2  s.  c o  m
    assertEquals("ERROR: Main class com.example.MissingMain does not exist.\n",
            console.getTextWrittenToStdErr());
}