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.apache.archiva.repository.maven2.MavenRepositoryProvider.java

private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) {
    ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
    stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
    stagingRepository.setLayout(repository.getLayout());
    stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
    stagingRepository.setBlockRedeployments(repository.isBlockRedeployments());
    stagingRepository.setRetentionPeriod(repository.getRetentionPeriod());
    stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots());
    stagingRepository.setStageRepoNeeded(false);

    String path = repository.getLocation();
    int lastIndex = path.replace('\\', '/').lastIndexOf('/');
    stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId());

    if (StringUtils.isNotBlank(repository.getIndexDir())) {
        Path indexDir = null;
        try {//from www .  j a va 2  s .c o  m
            indexDir = Paths
                    .get(new URI(repository.getIndexDir().startsWith("file://") ? repository.getIndexDir()
                            : "file://" + repository.getIndexDir()));
            if (indexDir.isAbsolute()) {
                Path newDir = indexDir.getParent()
                        .resolve(indexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
                log.debug("Changing index directory {} -> {}", indexDir, newDir);
                stagingRepository.setIndexDir(newDir.toString());
            } else {
                log.debug("Keeping index directory {}", repository.getIndexDir());
                stagingRepository.setIndexDir(repository.getIndexDir());
            }
        } catch (URISyntaxException e) {
            log.error("Could not parse index path as uri {}", repository.getIndexDir());
            stagingRepository.setIndexDir("");
        }
        // in case of absolute dir do not use the same
    }
    if (StringUtils.isNotBlank(repository.getPackedIndexDir())) {
        Path packedIndexDir = null;
        try {
            packedIndexDir = Paths.get(new URI(
                    repository.getPackedIndexDir().startsWith("file://") ? repository.getPackedIndexDir()
                            : "file://" + repository.getPackedIndexDir()));
            if (packedIndexDir.isAbsolute()) {
                Path newDir = packedIndexDir.getParent()
                        .resolve(packedIndexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
                log.debug("Changing index directory {} -> {}", packedIndexDir, newDir);
                stagingRepository.setPackedIndexDir(newDir.toString());
            } else {
                log.debug("Keeping index directory {}", repository.getPackedIndexDir());
                stagingRepository.setPackedIndexDir(repository.getPackedIndexDir());
            }
        } catch (URISyntaxException e) {
            log.error("Could not parse index path as uri {}", repository.getPackedIndexDir());
            stagingRepository.setPackedIndexDir("");
        }
        // in case of absolute dir do not use the same
    }
    stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression());
    stagingRepository.setReleases(repository.isReleases());
    stagingRepository.setRetentionCount(repository.getRetentionCount());
    stagingRepository.setScanned(repository.isScanned());
    stagingRepository.setSnapshots(repository.isSnapshots());
    stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation());
    // do not duplicate description
    //stagingRepository.getDescription("")
    return stagingRepository;
}

From source file:com.streamsets.pipeline.lib.io.TestSingleLineLiveFileReader.java

@Test
public void testTag() throws Exception {
    Path file = createFile(Arrays.asList("Hello1\r\n", "Hello\r\n"));
    LiveFile lf = new LiveFile(file);

    //multiple lines in one chunk
    LiveFileReader lfr = new SingleLineLiveFileReader(
            LogRollModeFactory.REVERSE_COUNTER.get(file.getFileName().toString(), ""), "tag", lf,
            Charset.defaultCharset(), 0, 20);
    Assert.assertTrue(lfr.hasNext());// w  w w  .  j  a  v  a2s  .  co m
    LiveFileChunk chunk = lfr.next(0);
    Assert.assertNotNull(chunk);
    Assert.assertEquals("tag", chunk.getTag());
    lfr.close();
}

From source file:com.streamsets.pipeline.lib.io.TestSingleLineLiveFileReader.java

@Test
public void testTruncateMultipleReads() throws Exception {
    Path file = createFile(Arrays.asList("Hello1234567890\n", "Hello\n"));
    LiveFile lf = new LiveFile(file);
    LiveFileReader lfr = new SingleLineLiveFileReader(
            LogRollModeFactory.REVERSE_COUNTER.get(file.getFileName().toString(), ""), null, lf,
            Charset.defaultCharset(), 0, 6);

    Assert.assertTrue(lfr.hasNext());/*from   w  w w.ja  v  a2s  .c om*/
    LiveFileChunk chunk = lfr.next(0);
    Assert.assertNotNull(chunk);
    Assert.assertTrue(chunk.isTruncated());
    Assert.assertEquals(0, chunk.getOffset());
    Assert.assertEquals(6, chunk.getLength());
    Assert.assertEquals("Hello1", readChunk(chunk));
    Assert.assertEquals(-6, lfr.getOffset());

    Assert.assertTrue(lfr.hasNext());
    chunk = lfr.next(0);
    Assert.assertNull(chunk);
    Assert.assertEquals(-12, lfr.getOffset());

    Assert.assertTrue(lfr.hasNext());
    chunk = lfr.next(0);
    Assert.assertNotNull(chunk);

    Assert.assertFalse(chunk.isTruncated());
    Assert.assertEquals(16, chunk.getOffset());
    Assert.assertEquals(6, chunk.getLength());
    Assert.assertEquals("Hello\n", readChunk(chunk));
    Assert.assertEquals(22, lfr.getOffset());

    Assert.assertTrue(lfr.hasNext());
    chunk = lfr.next(0);
    Assert.assertNull(chunk);
    Assert.assertEquals(22, lfr.getOffset());

    Assert.assertTrue(lfr.hasNext());
    chunk = lfr.next(0);
    Assert.assertNull(chunk);
    Assert.assertEquals(22, lfr.getOffset());

    Files.move(file, Paths.get(file.getParent().toString(), UUID.randomUUID().toString()));
    Thread.sleep(SingleLineLiveFileReader.REFRESH_INTERVAL + 1);

    Assert.assertFalse(lfr.hasNext());
    Assert.assertEquals(22, lfr.getOffset());

    lfr.close();
}

From source file:com.liferay.sync.engine.file.system.SyncWatchEventProcessor.java

protected boolean sanitizeFileName(Path filePath) {
    if (OSDetector.isWindows()) {
        return false;
    }//from  w w  w.  j a v  a  2s .  c o  m

    String fileName = String.valueOf(filePath.getFileName());

    String sanitizedFileName = FileUtil.getSanitizedFileName(fileName, FilenameUtils.getExtension(fileName));

    if (!sanitizedFileName.equals(fileName)) {
        String sanitizedFilePathName = FileUtil.getFilePathName(String.valueOf(filePath.getParent()),
                sanitizedFileName);

        sanitizedFilePathName = FileUtil.getNextFilePathName(sanitizedFilePathName);

        FileUtil.checkFilePath(filePath);

        FileUtil.moveFile(filePath, Paths.get(sanitizedFilePathName));

        return true;
    }

    return false;
}

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

@Test
public void shouldNotifyEventBusWhenDuplicateClassesAreFound() throws IOException {
    Path jarDirectory = folder.newFolder("jarDir");

    Path first = createZip(jarDirectory.resolve("a.jar"), "com/example/Main.class",
            "com/example/common/Helper.class");
    Path second = createZip(jarDirectory.resolve("b.jar"), "com/example/common/Helper.class");

    final Path outputPath = Paths.get("output.jar");
    JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(jarDirectory), outputPath,
            ImmutableSortedSet.of(first.getFileName(), second.getFileName()), "com.example.Main",
            /* manifest file */ null);
    ExecutionContext context = TestExecutionContext.newInstance();

    final BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
    context.getBuckEventBus().register(listener);

    step.execute(context);//w w w .  j  a v a 2s  . c  om
    final String expectedMessage = String.format(
            "Duplicate found when adding 'com/example/common/Helper.class' to '%s' from '%s'",
            outputPath.toAbsolutePath(), second.toAbsolutePath());
    assertThat(listener.getLogMessages(), hasItem(expectedMessage));
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

private void saveMRUBankFolder(String path) {
    Path pathE = Paths.get(path);

    String pathS = pathE.getParent().toString();
    String nameS = pathE.getFileName().toString();

    prefs.put("MRUBankFolder", pathS);
    prefs.put("MRUBankFileName", nameS);
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

private void saveMRUPatchFolder(String path) {
    Path pathE = Paths.get(path);

    String pathS = pathE.getParent().toString();
    String nameS = pathE.getFileName().toString();

    prefs.put("MRUPatchFolder", pathS);
    prefs.put("MRUPatchFileName", nameS);
}

From source file:com.splicemachine.storage.HNIOFileSystem.java

@Override
public void concat(Path target, Path... sources) throws IOException {
    org.apache.hadoop.fs.Path[] srcPaths = new org.apache.hadoop.fs.Path[sources.length];
    for (int i = 0; i < sources.length; i++) {
        srcPaths[i] = new org.apache.hadoop.fs.Path(sources[i].getParent().toString(),
                sources[i].getFileName().toString());
    }/*from   w  ww . j  a v a 2s.co m*/
    org.apache.hadoop.fs.Path targetPath = new org.apache.hadoop.fs.Path(target.getParent().toString(),
            target.getFileName().toString());

    if (isDistributedFS) {
        fs.concat(targetPath, srcPaths);
    } else {
        for (org.apache.hadoop.fs.Path src : srcPaths) {
            fs.copyFromLocalFile(true, false, src, targetPath);
        }
    }
}

From source file:com.nwn.NwnUpdater.java

/**
 * Scan local folders which should contain the files needed for the selected server
* If any files are missing, add them to the list of files to download
 * @return//from   ww w  . j  a v a2s . co  m
 */
private ArrayList<ServerFile> determineFilesToDownload() {
    currentGui.setTaskProgressBarValue(0);
    int currentProgress = 0;
    int progressIncrement;
    if (affectedFolders.size() > 0) {
        progressIncrement = 100 / affectedFolders.size();
    } else {
        progressIncrement = 100;
    }
    currentGui.appendOutputText("\nChecking local files");
    ArrayList<ServerFile> filesToDownload = new ArrayList<ServerFile>();
    for (String folder : affectedFolders) {
        Path folderPath = Paths.get(nwnRootPath.toString() + File.separator + folder);
        ArrayList<String> localFiles;
        try {
            localFiles = NwnFileHandler.getFileNamesInDirectory(folderPath);
        } catch (NoSuchFileException nsfe) {
            currentGui.appendOutputText(
                    "\nERROR: Folder " + folderPath.getFileName().toString() + " does not exist!");
            error[0] = true;
            return new ArrayList<ServerFile>();
        } catch (IOException ex) {
            currentGui.appendOutputText("\nERROR: Cannot parse local directory!");
            error[0] = true;
            return new ArrayList<ServerFile>();
        }
        for (ServerFile serverFile : serverFileList) {
            currentGui.appendOutputText(".");
            if (serverFile.getFileList() == null && serverFile.getFolder().equals(folder)
                    && !localFiles.contains(serverFile.getName())) {
                filesToDownload.add(serverFile);
            } else if (serverFile.getFileList() != null) {
                for (String file : serverFile.getFileList()) {
                    if (!localFiles.contains(file)
                            && NwnFileHandler.getFileExtension(file).equalsIgnoreCase(folder)
                            && !filesToDownload.contains(serverFile)) {

                        filesToDownload.add(serverFile);
                        break;
                    }
                }
            }
        }
        currentProgress = currentProgress + progressIncrement;
        currentGui.setTaskProgressBarValue(currentProgress);
    }
    currentGui.appendOutputText("done");
    return filesToDownload;
}

From source file:open.dolphin.client.MainWindowController.java

@FXML
protected void fileChoose() {
    FileChooser fc = new FileChooser();
    fc.setTitle("select file");
    fc.setInitialDirectory(new File(System.getProperty("user.home")));
    fc.getExtensionFilters().add(new ExtensionFilter("????", "*.*"));

    File f = fc.showOpenDialog(null);
    if (f != null) {
        try {/*from   ww  w. jav a2s . c  o m*/
            Path path = f.toPath();
            choiceFile.setText(path.getFileName().toString());
            for (String s : Files.readAllLines(path, Charset.forName("SJIS"))) {
                System.out.println(s);
            }
        } catch (IOException ex) {
            Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}