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:com.cinchapi.concourse.server.plugin.PluginConfiguration.java

/**
 * DO NOT CALL/* w w  w.j av a 2 s .c om*/
 * <p>
 * Provided for the plugin manager to create a local handler for every
 * plugin's preferences.
 * </p>
 * 
 * @param location
 */
protected PluginConfiguration(Path location) {
    if (Files.exists(location)) {
        try {
            this.prefs = new PreferencesHandler(location.toString()) {
            };
        } catch (ConfigurationException e) {
            throw Throwables.propagate(e);
        }
    } else {
        this.prefs = null;
    }
    addDefault(SystemPreference.HEAP_SIZE, DEFAULT_HEAP_SIZE_IN_BYTES);
}

From source file:eu.itesla_project.online.tools.CreateMclaMat.java

private void createMat(Network network, Path outputFolder) throws IOException {
    System.out.println("creating mat file for network" + network.getId());
    ArrayList<String> generatorsIds = NetworkUtils.getGeneratorsIds(network);
    ArrayList<String> loadsIds = NetworkUtils.getLoadsIds(network);
    SamplingNetworkData samplingNetworkData = new SamplingDataCreator(network, generatorsIds, loadsIds)
            .createSamplingNetworkData();
    Path networkDataMatFile = Files.createTempFile(outputFolder, "mcsamplerinput_" + network.getId() + "_",
            ".mat");
    System.out/*from  w ww  . j  a  v a 2 s . com*/
            .println("saving data of network " + network.getId() + " in file " + networkDataMatFile.toString());
    new MCSMatFileWriter(networkDataMatFile).writeSamplingNetworkData(samplingNetworkData);
}

From source file:its.tools.SonarlintInstaller.java

private Path locateZipInLocalMaven(String version) {
    String fileName = "sonarlint-daemon-" + version + ".zip";

    LOG.info("Searching for SonarLint Daemon {} in maven repositories", version);

    Path mvnRepo = getMavenLocalRepository();
    Path file = getMavenFilePath(mvnRepo, GROUP_ID, ARTIFACT_ID, version, fileName);

    if (!Files.exists(file)) {
        throw new IllegalArgumentException("Couldn't find in local repo: SonarLint Daemon " + file.toString());
    }//w  w w. ja v a 2 s.c o m
    return file;
}

From source file:ru.histone.staticrender.StaticRender.java

public void renderSite(final Path srcDir, final Path dstDir) {
    log.info("Running StaticRender for srcDir={}, dstDir={}", srcDir.toString(), dstDir.toString());
    Path contentDir = srcDir.resolve("content/");
    final Path layoutDir = srcDir.resolve("layouts/");

    FileVisitor<Path> layoutVisitor = new SimpleFileVisitor<Path>() {
        @Override/*w w  w  .  jav a2s.  c  o m*/
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.toString().endsWith("." + TEMPLATE_FILE_EXTENSION)) {
                ArrayNode ast = null;
                try {
                    ast = histone.parseTemplateToAST(new FileReader(file.toFile()));
                } catch (HistoneException e) {
                    throw new RuntimeException("Error parsing histone template:" + e.getMessage(), e);
                }

                final String fileName = file.getFileName().toString();
                String layoutId = fileName.substring(0,
                        fileName.length() - TEMPLATE_FILE_EXTENSION.length() - 1);
                layouts.put(layoutId, ast);
                if (log.isDebugEnabled()) {
                    log.debug("Layout found id='{}', file={}", layoutId, file);
                } else {
                    log.info("Layout found id='{}'", layoutId);
                }
            } else {
                final Path relativeFileName = srcDir.resolve("layouts").relativize(Paths.get(file.toUri()));
                final Path resolvedFile = dstDir.resolve(relativeFileName);
                if (!resolvedFile.getParent().toFile().exists()) {
                    Files.createDirectories(resolvedFile.getParent());
                }
                Files.copy(Paths.get(file.toUri()), resolvedFile, StandardCopyOption.REPLACE_EXISTING,
                        LinkOption.NOFOLLOW_LINKS);
            }
            return FileVisitResult.CONTINUE;
        }
    };

    FileVisitor<Path> contentVisitor = new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

            Scanner scanner = new Scanner(file, "UTF-8");
            scanner.useDelimiter("-----");

            String meta = null;
            StringBuilder content = new StringBuilder();

            if (!scanner.hasNext()) {
                throw new RuntimeException("Wrong format #1:" + file.toString());
            }

            if (scanner.hasNext()) {
                meta = scanner.next();
            }

            if (scanner.hasNext()) {
                content.append(scanner.next());
                scanner.useDelimiter("\n");
            }

            while (scanner.hasNext()) {
                final String next = scanner.next();
                content.append(next);

                if (scanner.hasNext()) {
                    content.append("\n");
                }
            }

            Map<String, String> metaYaml = (Map<String, String>) yaml.load(meta);

            String layoutId = metaYaml.get("layout");

            if (!layouts.containsKey(layoutId)) {
                throw new RuntimeException(MessageFormat.format("No layout with id='{0}' found", layoutId));
            }

            final Path relativeFileName = srcDir.resolve("content").relativize(Paths.get(file.toUri()));
            final Path resolvedFile = dstDir.resolve(relativeFileName);
            if (!resolvedFile.getParent().toFile().exists()) {
                Files.createDirectories(resolvedFile.getParent());
            }
            Writer output = new FileWriter(resolvedFile.toFile());
            ObjectNode context = jackson.createObjectNode();
            ObjectNode metaNode = jackson.createObjectNode();
            context.put("content", content.toString());
            context.put("meta", metaNode);
            for (String key : metaYaml.keySet()) {
                if (!key.equalsIgnoreCase("content")) {
                    metaNode.put(key, metaYaml.get(key));
                }
            }

            try {
                histone.evaluateAST(layoutDir.toUri().toString(), layouts.get(layoutId), context, output);
                output.flush();
            } catch (HistoneException e) {
                throw new RuntimeException("Error evaluating content: " + e.getMessage(), e);
            } finally {
                output.close();
            }

            return FileVisitResult.CONTINUE;
        }
    };

    try {
        Files.walkFileTree(layoutDir, layoutVisitor);
        Files.walkFileTree(contentDir, contentVisitor);
    } catch (Exception e) {
        throw new RuntimeException("Error during site render", e);
    }
}

From source file:misc.FileHandler.java

/**
 * Returns whether the given folder is shared. A folder is shared, if a
 * group access bundle exists in the folder.
 * /*from www. j  ava2 s .c  o  m*/
 * @param prefix
 *            the path to the client's root directory. May not be
 *            <code>null</code>.
 * @param folder
 *            a folder path relative to prefix which may contain a group
 *            access bundle. May not be <code>null</code>.
 * @return <code>true</code>, if and only if the given folder is shared.
 *         <code>false</code>, otherwise.
 */
public static boolean isShared(Path prefix, Path folder) {
    if (prefix == null) {
        throw new NullPointerException("prefix may not be null!");
    }
    if (folder == null) {
        throw new NullPointerException("folder may not be null!");
    }

    return !"".equals(folder.normalize().toString().trim()) && (Files
            .exists(Paths.get(prefix.toString(), folder.toString(), AccessBundle.ACCESS_BUNDLE_FILENAME)));
}

From source file:com.ejisto.util.IOUtils.java

public static boolean emptyDir(File file) {
    Path directory = file.toPath();
    if (!Files.isDirectory(directory)) {
        return true;
    }/*from ww  w  .  j a  v a 2 s .c  o m*/
    try {
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.delete(file);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                if (exc == null) {
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
                return FileVisitResult.TERMINATE;
            }
        });
    } catch (IOException e) {
        IOUtils.log.error(format("error while trying to empty the directory %s", directory.toString()), e);
        return false;
    }
    return true;
}

From source file:de.elomagic.carafile.client.CaraCloud.java

String getSubPath(final Path path) {
    Path p = path.subpath(basePath.getNameCount(), path.getNameCount());

    return p.toString().replace("\\", "/");
}

From source file:desktopsearch.WatchDir.java

private void UpdateDB(String Event, Path FullLocation) throws SQLException, IOException {

    File file = new File(FullLocation.toString());
    String path = file.getParent();
    String Name = file.getName();

    if (Name.contains("'")) {
        Name = Name.replace("'", "''");
    }//from   w  ww .  j  ava  2 s .  co m
    if (path.contains("'")) {
        path = path.replace("'", "''");
    }

    if (Event.equals("ENTRY_CREATE") && file.exists()) {
        FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(LastModifiedTime.toMillis());
        String Query;
        if (file.isFile()) {
            String Type = FilenameUtils.getExtension(FullLocation.toString());
            if (Type.endsWith("~") || Type.equals("")) {
                Type = "Text";
            }
            Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','" + Type + "','"
                    + calendar.getTime() + "'," + (file.length() / 1024) + ");";
        } else if (!Files.isSymbolicLink(FullLocation)) {
            long size = FileUtils.sizeOfDirectory(file);
            Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','FOLDER','" + calendar.getTime()
                    + "'," + size + ");";
        } else {
            Query = "INSERT INTO FileInfo VALUES('" + path + "','" + Name + "','LINK','" + calendar.getTime()
                    + "',0);";
        }
        statement.executeUpdate(Query);

    } else if (Event.equals("ENTRY_MODIFY")) {
        System.out.println(path + "/" + Name);
        FileTime LastModifiedTime = Files.getLastModifiedTime(FullLocation);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(LastModifiedTime.toMillis());
        String Query = "UPDATE FileInfo SET LastModified='" + calendar.getTime() + "' WHERE FileLocation='"
                + path + "' and FileName='" + Name + "';";
        System.out.println(Query);
        statement.executeUpdate(Query);

    } else if (Event.equals("ENTRY_DELETE")) {

        String Query = "DELETE FROM FileInfo WHERE FileLocation = '" + path + "' AND FileName = '" + Name
                + "';";
        statement.executeUpdate(Query);

    }
    connection.commit();

}

From source file:eu.forgetit.middleware.cmis.PIMORepositoryManager.java

public void fetchContentAndMetadata(String cmisId, Path destPath) {

    Path metadataPath = Paths.get(destPath.toString(), "metadata");

    Path contentPath = Paths.get(destPath.toString(), "content");

    try {/*from  w ww .jav  a2s. c  o  m*/

        String localContextCmisId = super.getObjectProperty(cmisId, "pimo:context");

        super.getObjectStream(localContextCmisId, metadataPath, "localContext.ttl");

        String contentType = getObjectType(cmisId);

        if (contentType.equals("pimo:document")) {

            Path contentFilePath = super.getObjectStream(cmisId, contentPath, null);

            logger.debug("Copied CMIS Object " + cmisId + " to file " + contentFilePath);

        }

    } catch (IOException e) {

        e.printStackTrace();
    }

}

From source file:edu.cwru.jpdg.Javac.java

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
    if (attr.isRegularFile()) {
        String ext = FilenameUtils.getExtension(file.toString());
        if (ext.equals("class")) {
            files.add(file.toFile());//from ww w  .  j  a  v  a 2 s.  c o m
        }
    }
    return FileVisitResult.CONTINUE;
}