Example usage for java.nio.file Path toString

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

Introduction

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

Prototype

String toString();

Source Link

Document

Returns the string representation of this path.

Usage

From source file:azkaban.soloserver.AzkabanSingleServerTest.java

private static String getSqlScriptsDir() throws IOException {
    // Dummy because any resource file works.
    Path resources = Paths.get(getConfPath()).getParent();
    Path azkabanRoot = resources.getParent().getParent().getParent().getParent();

    File sqlScriptDir = Paths.get(azkabanRoot.toString(), AZKABAN_DB_SQL_PATH).toFile();
    return sqlScriptDir.getCanonicalPath();
}

From source file:azkaban.webapp.AzkabanWebServerTest.java

private static String getSqlScriptsDir() throws IOException {
    // Dummy because any resource file works.
    final String dummyResourcePath = getUserManagerXmlFile();
    Path resources = Paths.get(dummyResourcePath).getParent();
    Path azkabanRoot = resources.getParent().getParent().getParent().getParent();

    File sqlScriptDir = Paths.get(azkabanRoot.toString(), AZKABAN_DB_SQL_PATH).toFile();
    return sqlScriptDir.getCanonicalPath();
}

From source file:de.sanandrew.mods.turretmod.registry.assembly.TurretAssemblyRecipes.java

private static boolean processRecipeJson(Path file, final ITurretAssemblyRegistry registry) {
    return FilenameUtils.getName(file.toString()).startsWith("group_")
            || processJson(file, json -> registerJsonRecipes(json, registry));
}

From source file:com.liferay.sync.engine.util.FileUtil.java

public static String getFilePathName(String first, String... more) {
    FileSystem fileSystem = FileSystems.getDefault();

    Path filePath = fileSystem.getPath(first, more);

    return filePath.toString();
}

From source file:com.thesmartguild.firmloader.lib.tftp.TFTPServerFactory.java

public static TFTPServer instantiate(File file) {
    try {/* www .  j a v a2s.co m*/
        TFTPServer TFTPServer_;
        Path tmpFilePath = TFTPServerFactory.createTempDirectory();
        Path filePath = Files.copy(file.toPath(), Paths.get(tmpFilePath.toString(), file.getName()),
                StandardCopyOption.REPLACE_EXISTING);
        filePath.toFile().deleteOnExit();
        TFTPServer_ = new TFTPServer(tmpFilePath.toFile(), tmpFilePath.toFile(), ServerMode.GET_ONLY);
        TFTPServer_.setLog(System.out);
        TFTPServer_.setLogError(System.out);
        return TFTPServer_;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:de.fatalix.book.importer.CalibriImporter.java

public static void processBooks(Path root, String solrURL, String solrCore, final int batchSize)
        throws IOException, SolrServerException {
    final SolrServer solrServer = SolrHandler.createConnection(solrURL, solrCore);
    final List<BookEntry> bookEntries = new ArrayList<>();
    Files.walkFileTree(root, new SimpleFileVisitor<Path>() {

        @Override/*ww  w  . j a  v  a 2s .c  o m*/
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            if (dir.toString().contains("__MACOSX")) {
                return FileVisitResult.SKIP_SUBTREE;
            }
            try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir)) {
                BookEntry bookEntry = new BookEntry().setUploader("admin");
                for (Path path : directoryStream) {
                    if (!Files.isDirectory(path)) {
                        if (path.toString().contains(".opf")) {
                            bookEntry = parseOPF(path, bookEntry);
                        }
                        if (path.toString().contains(".mobi")) {
                            bookEntry.setMobi(Files.readAllBytes(path)).setMimeType("MOBI");
                        }
                        if (path.toString().contains(".epub")) {
                            bookEntry.setEpub(Files.readAllBytes(path));
                        }
                        if (path.toString().contains(".jpg")) {
                            bookEntry.setCover(Files.readAllBytes(path));
                            ByteArrayOutputStream output = new ByteArrayOutputStream();
                            Thumbnails.of(new ByteArrayInputStream(bookEntry.getCover())).size(130, 200)
                                    .toOutputStream(output);
                            bookEntry.setThumbnail(output.toByteArray());
                            bookEntry.setThumbnailGenerated("done");
                        }
                    }
                }
                if (bookEntry.getMobi() != null || bookEntry.getEpub() != null) {
                    bookEntries.add(bookEntry);
                    if (bookEntries.size() > batchSize) {
                        System.out.println("Adding " + bookEntries.size() + " Books...");
                        try {
                            SolrHandler.addBeans(solrServer, bookEntries);
                        } catch (SolrServerException ex) {
                            System.out.println(ex.getMessage());
                            ex.printStackTrace();
                        }
                        bookEntries.clear();
                    }
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return super.preVisitDirectory(dir, attrs);
        }
    });
}

From source file:com.liferay.sync.engine.util.MSOfficeFileUtil.java

public static boolean isTempRenamedFile(Path sourceFilePath, Path targetFilePath) {

    String extension = FilenameUtils.getExtension(sourceFilePath.toString());

    if (extension.equals("pub")) {
        String fileName = String.valueOf(targetFilePath.getFileName());

        if (fileName.startsWith("pub") && fileName.endsWith(".tmp")) {
            return true;
        }//from w  w w.  j a v  a  2  s.c  o m
    } else if (hasExtension(extension, _excelExtensions) || hasExtension(extension, _powerpointExtensions)) {

        Matcher matcher = _tempRenamedFilePattern.matcher(String.valueOf(targetFilePath.getFileName()));

        if (matcher.matches()) {
            return true;
        }
    } else if (hasExtension(extension, _wordExtensions)) {
        String fileName = String.valueOf(targetFilePath.getFileName());

        if (fileName.startsWith("~WR") && fileName.endsWith(".tmp")) {
            return true;
        }
    }

    return false;
}

From source file:com.kotcrab.vis.editor.util.FileUtils.java

public static String relativize(FileHandle base, FileHandle absolute) {
    Path pathAbsolute = Paths.get(absolute.path());
    Path pathBase = Paths.get(base.path());
    Path pathRelative = pathBase.relativize(pathAbsolute);
    String path = pathRelative.toString().replace("\\", "/");
    if (absolute.isDirectory())
        path += "/";
    return path;/*ww w  . jav  a2 s  .  co  m*/
}

From source file:gndata.lib.config.ProjectConfig.java

/**
 * Loads the project settings from a json file.
 * If the file does not exist, a default configuration is created.
 *
 * @param projectPath   Path to the project config file.
 *
 * @return The loaded configuration./* w  ww  . j  a v a2 s. c  o m*/
 *
 * @throws IOException If the loading fails.
 */
public static ProjectConfig load(String projectPath) throws IOException {
    Path absPath = Paths.get(projectPath).toAbsolutePath().normalize();
    Path filePath = absPath.resolve(IN_PROJECT_PATH);

    if (Files.exists(filePath)) {
        ProjectConfig config = AbstractConfig.load(filePath.toString(), ProjectConfig.class);
        config.setProjectPath(absPath.toString());

        return config;
    } else {
        ProjectConfig config = new ProjectConfig();
        // set defaults here if necessary
        config.setFilePath(filePath.toString());
        config.setProjectPath(absPath.toString());

        config.store();
        return config;
    }
}

From source file:com.dangdang.ddframe.job.example.JavaMain.java

private static String buildScriptCommandLine() throws IOException {
    if (System.getProperties().getProperty("os.name").contains("Windows")) {
        return Paths.get(JavaMain.class.getResource("/script/demo.bat").getPath().substring(1)).toString();
    }/*from   ww  w .j a v  a  2s . c o m*/
    Path result = Paths.get(JavaMain.class.getResource("/script/demo.sh").getPath());
    Files.setPosixFilePermissions(result, PosixFilePermissions.fromString("rwxr-xr-x"));
    return result.toString();
}