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.aol.advertising.qiao.injector.file.watcher.QiaoFileManager.java

private boolean nameContainsChecksum(Path filePath, long checksum) {
    String name = filePath.getFileName().toString();
    String cksum = String.format(".%d", checksum);
    if (name.contains(cksum))
        return true;

    return false;
}

From source file:com.aol.advertising.qiao.injector.file.watcher.QiaoFileManager.java

private Path resolveNewFilePath(Path sourceFilePath, long checksum) {
    String fname = sourceFilePath.getFileName().toString() + "." + checksum;
    return sourceFilePath.resolveSibling(fname);
}

From source file:com.facebook.buck.features.zip.rules.ZipRuleIntegrationTest.java

@Test
public void shouldNotMergeSourceJarsIfRequested() throws Exception {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "zip-merge", tmp);
    workspace.setUp();/*from  ww w  .j  a  va2  s  . c o  m*/

    Path zip = workspace.buildAndReturnOutput("//example:no-merge");

    // Gather expected file names
    Path sourceJar = workspace.buildAndReturnOutput("//example:cake#src");
    Path actualJar = workspace.buildAndReturnOutput("//example:cake");

    try (ZipFile zipFile = new ZipFile(zip.toFile())) {
        ZipArchiveEntry item = zipFile.getEntry(sourceJar.getFileName().toString());
        assertThat(item, Matchers.notNullValue());

        item = zipFile.getEntry(actualJar.getFileName().toString());
        assertThat(item, Matchers.notNullValue());

        item = zipFile.getEntry("cake.txt");
        assertThat(item, Matchers.notNullValue());
    }
}

From source file:edu.mit.lib.handbag.Controller.java

public void initialize() {

    Image wfIm = new Image(getClass().getResourceAsStream("/SiteMap.png"));
    workflowLabel.setGraphic(new ImageView(wfIm));
    workflowLabel.setContentDisplay(ContentDisplay.BOTTOM);

    workflowChoiceBox.addEventHandler(ActionEvent.ACTION, event -> {
        if (workflowChoiceBox.getItems().size() != 0) {
            return;
        }/*from  w  ww. j av a2 s . co  m*/
        ObservableList<Workflow> wflowList = FXCollections.observableArrayList(loadWorkflows());
        workflowChoiceBox.setItems(wflowList);
        workflowChoiceBox.getSelectionModel().selectedIndexProperty().addListener((ov, value, new_value) -> {
            int newVal = (int) new_value;
            if (newVal != -1) {
                Workflow newSel = workflowChoiceBox.getItems().get(newVal);
                if (newSel != null) {
                    workflowLabel.setText(newSel.getName());
                    generateBagName(newSel.getBagNameGenerator());
                    bagLabel.setText(bagName);
                    sendButton.setText(newSel.getDestinationName());
                    setMetadataList(newSel);
                }
            }
        });
    });

    Image bagIm = new Image(getClass().getResourceAsStream("/Bag.png"));
    bagLabel.setGraphic(new ImageView(bagIm));
    bagLabel.setContentDisplay(ContentDisplay.BOTTOM);

    Image sendIm = new Image(getClass().getResourceAsStream("/Cabinet.png"));
    sendButton.setGraphic(new ImageView(sendIm));
    sendButton.setContentDisplay(ContentDisplay.BOTTOM);
    sendButton.setDisable(true);
    sendButton.setOnAction(e -> transmitBag());

    Image trashIm = new Image(getClass().getResourceAsStream("/Bin.png"));
    trashButton.setGraphic(new ImageView(trashIm));
    trashButton.setContentDisplay(ContentDisplay.BOTTOM);
    trashButton.setDisable(true);
    trashButton.setOnAction(e -> reset(false));

    TreeItem<PathRef> rootItem = new TreeItem<>(new PathRef("", Paths.get("data")));
    rootItem.setExpanded(true);
    payloadTreeView.setRoot(rootItem);
    payloadTreeView.setOnDragOver(event -> {
        if (event.getGestureSource() != payloadTreeView && event.getDragboard().getFiles().size() > 0) {
            event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
        }
        event.consume();
    });
    payloadTreeView.setOnDragDropped(event -> {
        Dragboard db = event.getDragboard();
        boolean success = false;
        if (db.getFiles().size() > 0) {
            for (File dragFile : db.getFiles()) {
                if (dragFile.isDirectory()) {
                    // explode directory and add expanded relative paths to tree
                    relPathSB = new StringBuilder();
                    try {
                        Files.walkFileTree(dragFile.toPath(), new SimpleFileVisitor<Path>() {
                            @Override
                            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                                    throws IOException {
                                relPathSB.append(dir.getFileName()).append("/");
                                return FileVisitResult.CONTINUE;
                            }

                            @Override
                            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                                    throws IOException {
                                payloadTreeView.getRoot().getChildren()
                                        .add(new TreeItem<>(new PathRef(relPathSB.toString(), file)));
                                bagSize += Files.size(file);
                                return FileVisitResult.CONTINUE;
                            }
                        });
                    } catch (IOException ioe) {
                    }
                } else {
                    payloadTreeView.getRoot().getChildren()
                            .add(new TreeItem<>(new PathRef("", dragFile.toPath())));
                    bagSize += dragFile.length();
                }
            }
            bagSizeLabel.setText(scaledSize(bagSize, 0));
            success = true;
            updateButtons();
        }
        event.setDropCompleted(success);
        event.consume();
    });

    metadataPropertySheet.setModeSwitcherVisible(false);
    metadataPropertySheet.setDisable(false);
    metadataPropertySheet.addEventHandler(KeyEvent.ANY, event -> {
        checkComplete(metadataPropertySheet.getItems());
        event.consume();
    });
}

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

private void loadSharedParameters(Path instanceDir, Map<String, SharedParameters> 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, SharedParameters.class,
                this.sharedParameters.get(instanceId)));
    } else {/*from  www  .  ja va  2  s .c o m*/
        log.trace("Not loading shared parameters from {}, " + "file does not exist", sharedParametersPath);
    }
}

From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java

private void backupFile() throws IOException {
    final Path sourceFile = picture.getFile();
    final String parentPath = sourceFile.getParent().toString();
    final String hashedPath = DigestUtils.md5Hex(parentPath + backupId);

    final Path targetDir = BACKUP_DIR.resolve(hashedPath);
    Files.createDirectories(targetDir);

    Files.copy(sourceFile, targetDir.resolve(sourceFile.getFileName()));
}

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

private void loadPrivateParameters(Path instanceDir, Map<String, PrivateParameters> 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, PrivateParameters.class,
                this.privateParameters.get(instanceId)));
    } else {/*from  ww w . ja  v a  2s  . com*/
        log.trace("Not loading private parameters from {}, " + "file does not exist", privateParametersPath);
    }
}

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

/**
 * Returns the name of the given importable item.  This is the final name of the item, as it would appear in the repository,
 * after metadata renames are taken into account.
 * // w w  w. j a v  a  2 s.  com
 * @param importableItem The importableItem with which to 
 * @param metadata MetadataLoader.Metadata
 * @return the name of the given importable item
 */
protected final String getImportableItemName(ImportableItem importableItem, MetadataLoader.Metadata metadata) {
    String result = null;

    // Step 1: attempt to get name from metadata
    if (metadata != null) {
        result = (String) metadata.getProperties().get(ContentModel.PROP_NAME);
    }

    // Step 2: attempt to get name from metadata file
    if (result == null && importableItem != null && importableItem.getHeadRevision() != null) {
        Path metadataFile = importableItem.getHeadRevision().getMetadataFile();

        if (metadataFile != null) {
            final String metadataFileName = metadataFile.getFileName().toString();

            result = metadataFileName.substring(0,
                    metadataFileName.length() - (MetadataLoader.METADATA_SUFFIX.length()
                            + metadataLoader.getMetadataFileExtension().length()));
        }
    }

    // Step 3: read the parent filename from the item itself
    if (result == null && importableItem != null) {
        result = importableItem.getHeadRevision().getContentFile().getFileName().toString();
    }

    return (result);
}

From source file:io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder.java

@Override
public Path addFileExtension(Path file) {
    return file.resolveSibling(addFileExtension(file.getFileName().toString()));
}

From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java

/**
 * This test cannot run on Windows without extra privileges
 *///  w  w  w  . j a  v a 2s  .c o  m
@Test
public void testSymlink() throws IOException {
    assumeFalse(Platform.isWindows());
    final Path tempDir = Files.createTempDirectory("ds3_file_object_putter_");
    final Path tempPath = Files.createTempFile(tempDir, "temp_", ".txt");

    try {
        try (final SeekableByteChannel channel = Files.newByteChannel(tempPath, StandardOpenOption.CREATE,
                StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
            channel.write(ByteBuffer.wrap(testData));
        }

        final Path symLinkPath = tempDir.resolve("sym_" + tempPath.getFileName().toString());
        Files.createSymbolicLink(symLinkPath, tempPath);

        getFileWithPutter(tempDir, symLinkPath);
    } finally {
        Files.deleteIfExists(tempPath);
        Files.deleteIfExists(tempDir);
    }
}