Example usage for java.nio.file Path toAbsolutePath

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

Introduction

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

Prototype

Path toAbsolutePath();

Source Link

Document

Returns a Path object representing the absolute path of this path.

Usage

From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowExporterDialog.java

/**
 * Create the dialog./* ww  w . j  a va 2 s. c  o m*/
 * 
 * @param tvShowsToExport
 *          the movies to export
 */
public TvShowExporterDialog(List<TvShow> tvShowsToExport) {
    super(BUNDLE.getString("tvshow.export"), "tvShowExporter"); //$NON-NLS-1$
    setBounds(5, 5, 600, 300);

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("300dlu:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, }));

    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(0.7);
    getContentPane().add(splitPane, "2, 2, fill, fill");

    JScrollPane scrollPane = new JScrollPane();
    splitPane.setLeftComponent(scrollPane);

    list = new JList();
    scrollPane.setViewportView(list);

    JPanel panelExporterDetails = new JPanel();
    splitPane.setRightComponent(panelExporterDetails);
    panelExporterDetails.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    lblTemplateName = new JLabel("");
    panelExporterDetails.add(lblTemplateName, "2, 2, 3, 1");

    lblUrl = new JLabel("");
    panelExporterDetails.add(lblUrl, "2, 4, 3, 1");

    chckbxTemplateWithDetail = new JCheckBox("");
    chckbxTemplateWithDetail.setEnabled(false);
    panelExporterDetails.add(chckbxTemplateWithDetail, "2, 6");

    JLabel lblDetails = new JLabel(BUNDLE.getString("export.detail")); //$NON-NLS-1$
    panelExporterDetails.add(lblDetails, "4, 6");

    JScrollPane scrollPaneDescription = new JScrollPane();
    panelExporterDetails.add(scrollPaneDescription, "2, 8, 3, 1, fill, fill");

    tpDescription = new JTextPane();
    scrollPaneDescription.setViewportView(tpDescription);
    splitPane.setDividerLocation(300);

    JPanel panel = new JPanel();
    getContentPane().add(panel, "2, 4, fill, fill");
    panel.setLayout(
            new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, }, new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, }));

    tfExportDir = new JTextField();
    panel.add(tfExportDir, "1, 1, fill, default");
    tfExportDir.setColumns(10);

    JButton btnSetDestination = new JButton(BUNDLE.getString("export.setdestination")); //$NON-NLS-1$
    panel.add(btnSetDestination, "3, 1");
    btnSetDestination.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("export.selectdirectory")); //$NON-NLS-1$
            if (file != null) {
                tfExportDir.setText(file.toAbsolutePath().toString());
            }
        }
    });

    JPanel panelButtons = new JPanel();
    panelButtons.setLayout(new EqualsLayout(5));
    getContentPane().add(panelButtons, "2, 6, fill, fill");

    JButton btnExport = new JButton("Export");
    btnExport.setIcon(IconManager.EXPORT);
    btnExport.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (StringUtils.isBlank(tfExportDir.getText())) {
                return;
            }
            // check selected template
            int index = list.getSelectedIndex();
            if (index < 0) {
                return;
            }

            ExportTemplate selectedTemplate = templatesFound.get(index);
            if (selectedTemplate != null) {
                try {
                    TvShowExporter exporter = new TvShowExporter(Paths.get(selectedTemplate.getPath()));
                    exporter.export(tvShows, Paths.get(tfExportDir.getText()));
                } catch (Exception e) {
                    LOGGER.error("Error exporting tv shows: ", e);
                }
                setVisible(false);
            }
        }
    });
    panelButtons.add(btnExport);

    JButton btnCancel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    btnCancel.setIcon(IconManager.CANCEL);
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setVisible(false);
        }
    });
    panelButtons.add(btnCancel);

    tvShows = tvShowsToExport;
    templatesFound = TvShowExporter.findTemplates(TemplateType.TV_SHOW);
    initDataBindings();
}

From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurerTest.java

@Test
public void testTestSuiteFolder() throws IOException {
    PropertyHolder properties = BeanLoader.loadBean(PropertyHolder.class);
    Path tsFolder = Paths.get(properties.getTestSuiteFolder());

    assertTrue(Files.exists(tsFolder), "test suite folder doesn't exists or is not set correctly");
    BaseTest.assertContains(tsFolder.toAbsolutePath().toString(), PPROPERTY_TEST_FOLDER_PATH);
}

From source file:org.opencb.opencga.app.cli.CommandExecutor.java

/**
 * This method attempts to load general configuration from CLI 'conf' parameter, if not exists then loads JAR storage-configuration.yml.
 *
 * @throws IOException If any IO problem occurs
 *///from ww  w  .  j a v a2 s  .c  om
public void loadOpencgaConfiguration() throws IOException {
    FileUtils.checkDirectory(Paths.get(this.conf));

    // We load configuration file either from app home folder or from the JAR
    Path path = Paths.get(this.conf).resolve("configuration.yml");
    if (path != null && Files.exists(path)) {
        logger.debug("Loading configuration from '{}'", path.toAbsolutePath());
        this.configuration = Configuration.load(new FileInputStream(path.toFile()));
    } else {
        logger.debug("Loading configuration from JAR file");
        this.configuration = Configuration
                .load(ClientConfiguration.class.getClassLoader().getResourceAsStream("configuration.yml"));
    }
}

From source file:org.apache.zeppelin.interpreter.launcher.SparkInterpreterLauncherTest.java

@Test
public void testYarnClusterMode_2() throws IOException {
    ZeppelinConfiguration zConf = new ZeppelinConfiguration();
    SparkInterpreterLauncher launcher = new SparkInterpreterLauncher(zConf, null);
    Properties properties = new Properties();
    properties.setProperty("SPARK_HOME", "/user/spark");
    properties.setProperty("property_1", "value_1");
    properties.setProperty("master", "yarn");
    properties.setProperty("spark.submit.deployMode", "cluster");
    properties.setProperty("spark.files", "file_1");
    properties.setProperty("spark.jars", "jar_1");

    InterpreterOption option = new InterpreterOption();
    option.setUserImpersonate(true);/*from  w  ww .ja va  2s .c  om*/
    InterpreterLaunchContext context = new InterpreterLaunchContext(properties, option, null, "user1",
            "intpGroupId", "groupId", "spark", "spark", 0, "host");
    Path localRepoPath = Paths.get(zConf.getInterpreterLocalRepoPath(), context.getInterpreterSettingId());
    FileUtils.deleteDirectory(localRepoPath.toFile());
    Files.createDirectories(localRepoPath);
    Files.createFile(Paths.get(localRepoPath.toAbsolutePath().toString(), "test.jar"));

    InterpreterClient client = launcher.launch(context);
    assertTrue(client instanceof RemoteInterpreterManagedProcess);
    RemoteInterpreterManagedProcess interpreterProcess = (RemoteInterpreterManagedProcess) client;
    assertEquals("spark", interpreterProcess.getInterpreterSettingName());
    assertTrue(interpreterProcess.getInterpreterDir().endsWith("/interpreter/spark"));
    assertTrue(interpreterProcess.getLocalRepoDir().endsWith("/local-repo/groupId"));
    assertEquals(zConf.getInterpreterRemoteRunnerPath(), interpreterProcess.getInterpreterRunner());
    assertTrue(interpreterProcess.getEnv().size() >= 3);
    assertEquals("/user/spark", interpreterProcess.getEnv().get("SPARK_HOME"));
    assertEquals("true", interpreterProcess.getEnv().get("ZEPPELIN_SPARK_YARN_CLUSTER"));
    assertEquals(
            " --master yarn --conf spark.files='file_1',.//conf/log4j_yarn_cluster.properties --conf spark.jars='jar_1' --conf spark.submit.deployMode='cluster' --conf spark.yarn.isPython=true --conf spark.yarn.submit.waitAppCompletion=false --proxy-user user1 --jars "
                    + Paths.get(localRepoPath.toAbsolutePath().toString(), "test.jar").toString(),
            interpreterProcess.getEnv().get("ZEPPELIN_SPARK_CONF"));
    Files.deleteIfExists(Paths.get(localRepoPath.toAbsolutePath().toString(), "test.jar"));
    FileUtils.deleteDirectory(localRepoPath.toFile());
}

From source file:com.qwazr.library.archiver.ArchiverTool.java

public void addToZipFile(final String entryName, final String filePath, final ZipOutputStream zos)
        throws IOException {
    final Path srcFile = Paths.get(filePath);
    if (!Files.exists(srcFile))
        throw new FileNotFoundException("The file does not exists: " + srcFile.toAbsolutePath());
    try (final InputStream in = Files.newInputStream(srcFile);
            final BufferedInputStream bIn = new BufferedInputStream(in)) {
        ZipEntry zipEntry = new ZipEntry(entryName);
        zos.putNextEntry(zipEntry);/* w ww  .  j a  v a  2  s  .  c  om*/
        IOUtils.copy(bIn, zos);
        zos.closeEntry();
    }
}

From source file:org.niord.proxy.rest.AbstractNiordService.java

/**
 * Fetches a file from Niord and saves it in the given path.
 * Returns null if the file cannot be fetched
 *
 * @param url the Niord URL// ww  w  .j av  a2 s.  c  o m
 * @param path the path to save the file in
 * @return the result or null in case of an error
 */
public Path fetchNiordFile(String url, Path path) {
    long t0 = System.currentTimeMillis();

    try {
        HttpURLConnection con = createHttpUrlConnection(url);

        try (InputStream is = con.getInputStream()) {
            FileUtils.copyInputStreamToFile(is, path.toFile());
        }

        log.log(Level.INFO, String.format("Saved Niord file %s to %s in %s ms", url, path.toAbsolutePath(),
                System.currentTimeMillis() - t0));

        return path;

    } catch (Exception e) {
        log.log(Level.SEVERE, String.format("Failed fetching Niord file %s. Error: %s", url, e.getMessage()));
        return null;
    }
}

From source file:org.tinymediamanager.ui.movies.dialogs.MovieExporterDialog.java

/**
 * Create the dialog./*w  w w  .  jav a 2  s . c  o  m*/
 * 
 * @param moviesToExport
 *          the movies to export
 */
public MovieExporterDialog(List<Movie> moviesToExport) {
    super(BUNDLE.getString("movie.export"), "movieExporter"); //$NON-NLS-1$
    setBounds(5, 5, 600, 300);

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("300dlu:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, }));

    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(0.7);
    getContentPane().add(splitPane, "2, 2, fill, fill");

    JScrollPane scrollPane = new JScrollPane();
    splitPane.setLeftComponent(scrollPane);

    list = new JList();
    scrollPane.setViewportView(list);

    JPanel panelExporterDetails = new JPanel();
    splitPane.setRightComponent(panelExporterDetails);
    panelExporterDetails.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    lblTemplateName = new JLabel("");
    panelExporterDetails.add(lblTemplateName, "2, 2, 3, 1");

    lblUrl = new JLabel("");
    panelExporterDetails.add(lblUrl, "2, 4, 3, 1");

    chckbxTemplateWithDetail = new JCheckBox("");
    chckbxTemplateWithDetail.setEnabled(false);
    panelExporterDetails.add(chckbxTemplateWithDetail, "2, 6");

    JLabel lblDetails = new JLabel(BUNDLE.getString("export.detail")); //$NON-NLS-1$
    panelExporterDetails.add(lblDetails, "4, 6");

    JScrollPane scrollPaneDescription = new JScrollPane();
    panelExporterDetails.add(scrollPaneDescription, "2, 8, 3, 1, fill, fill");

    tpDescription = new JTextPane();
    scrollPaneDescription.setViewportView(tpDescription);
    splitPane.setDividerLocation(300);

    JPanel panelDestination = new JPanel();
    getContentPane().add(panelDestination, "2, 4, fill, fill");
    panelDestination
            .setLayout(
                    new FormLayout(
                            new ColumnSpec[] { ColumnSpec.decode("150dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC,
                                    FormSpecs.DEFAULT_COLSPEC, },
                            new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, }));

    tfExportDir = new JTextField();
    panelDestination.add(tfExportDir, "1, 1, fill, default");
    tfExportDir.setColumns(10);

    JButton btnSetDestination = new JButton(BUNDLE.getString("export.setdestination")); //$NON-NLS-1$
    panelDestination.add(btnSetDestination, "3, 1");
    btnSetDestination.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("export.selectdirectory")); //$NON-NLS-1$
            if (file != null) {
                tfExportDir.setText(file.toAbsolutePath().toString());
            }
        }
    });

    JPanel panelButtons = new JPanel();
    panelButtons.setLayout(new EqualsLayout(5));
    getContentPane().add(panelButtons, "2, 6, fill, fill");

    JButton btnExport = new JButton("Export");
    btnExport.setIcon(IconManager.EXPORT);
    btnExport.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (StringUtils.isBlank(tfExportDir.getText())) {
                return;
            }
            // check selected template
            int index = list.getSelectedIndex();
            if (index < 0) {
                return;
            }

            ExportTemplate selectedTemplate = templatesFound.get(index);
            if (selectedTemplate != null) {
                try {
                    MovieExporter exporter = new MovieExporter(Paths.get(selectedTemplate.getPath()));
                    exporter.export(movies, Paths.get(tfExportDir.getText()));
                } catch (Exception e) {
                    LOGGER.error("Error exporting movies: ", e);
                }
                setVisible(false);
            }
        }
    });
    panelButtons.add(btnExport);

    JButton btnCancel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    btnCancel.setIcon(IconManager.CANCEL);
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setVisible(false);
        }
    });
    panelButtons.add(btnCancel);

    movies = moviesToExport;
    templatesFound = MovieExporter.findTemplates(TemplateType.MOVIE);
    initDataBindings();
}

From source file:com.facebook.buck.util.unarchive.UnzipTest.java

@Test
public void testParentDirPaths() throws InterruptedException, IOException {

    try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
        // It seems very unlikely that a zip file would contain ".." paths, but handle it anyways.
        zip.putArchiveEntry(new ZipArchiveEntry("foo/bar/"));
        zip.closeArchiveEntry();/*w w w .j  a v  a 2 s  . c o m*/
        zip.putArchiveEntry(new ZipArchiveEntry("foo/bar/../"));
        zip.closeArchiveEntry();
    }

    Path extractFolder = tmpFolder.newFolder();

    ArchiveFormat.ZIP.getUnarchiver().extractArchive(new DefaultProjectFilesystemFactory(),
            zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(),
            ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES);
    assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("foo")));
    assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("foo/bar")));
}

From source file:codes.thischwa.c5c.impl.LocalConnector.java

@Override
public GenericConnector.FileProperties getInfo(String backendPath, boolean needSize) throws C5CException {
    Path path = buildRealPath(backendPath);
    if (!Files.exists(path)) {
        logger.error("Requested file not exits: {}", path.toAbsolutePath());
        throw new FilemanagerException(FilemanagerAction.INFO, FilemanagerException.Key.FileNotExists,
                backendPath);//from w  ww .  j  a v  a2 s.c  om
    }
    return constructFileInfo(path, needSize);
}

From source file:com.facebook.buck.util.unarchive.UnzipTest.java

@Test
public void testExtractSymlink() throws InterruptedException, IOException {
    assumeThat(Platform.detect(), Matchers.is(Matchers.not(Platform.WINDOWS)));

    // Create a simple zip archive using apache's commons-compress to store executable info.
    try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
        ZipArchiveEntry entry = new ZipArchiveEntry("link.txt");
        entry.setUnixMode((int) MostFiles.S_IFLNK);
        String target = "target.txt";
        entry.setSize(target.getBytes(Charsets.UTF_8).length);
        entry.setMethod(ZipEntry.STORED);
        zip.putArchiveEntry(entry);//  w  ww .  j a  v a2 s.c o  m
        zip.write(target.getBytes(Charsets.UTF_8));
        zip.closeArchiveEntry();
    }

    Path extractFolder = tmpFolder.newFolder();

    ArchiveFormat.ZIP.getUnarchiver().extractArchive(new DefaultProjectFilesystemFactory(),
            zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(), ExistingFileMode.OVERWRITE);
    Path link = extractFolder.toAbsolutePath().resolve("link.txt");
    assertTrue(Files.isSymbolicLink(link));
    assertThat(Files.readSymbolicLink(link).toString(), Matchers.equalTo("target.txt"));
}