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:fr.duminy.jbackup.core.ConfigurationManagerTest.java

public static BackupConfiguration createConfiguration(String configName, Path targetDirectory) {
    final BackupConfiguration config = new BackupConfiguration();

    config.setName(configName);// w  w  w .j  a  v  a 2 s.  c  o m
    config.setArchiveFactory(ZipArchiveFactory.INSTANCE);
    Path targetPath = (targetDirectory == null) ? Paths.get(TARGET_DIRECTORY)
            : targetDirectory.toAbsolutePath();
    config.setTargetDirectory(targetPath.toString());
    config.addSource(Paths.get("aSource").toAbsolutePath(), "aDirFilter", "aFileFilter");
    config.addSource(Paths.get("aSource2").toAbsolutePath());
    config.addSource(Paths.get("anotherSource").toAbsolutePath(), "anotherDirFilter", "anotherFileFilter");

    return config;
}

From source file:com.excelsiorjet.api.util.Utils.java

public static void copyQuietly(Path source, Path target) {
    // We could just use Maven FileUtils.copyDirectory method but it copies a directory as a whole
    // while here we copy only those files that were changed from previous build.
    try {//  ww  w.  ja v a  2s  . c  om
        copyDirectory(source, target);
    } catch (IOException e) {
        logger.warn(s("TestRunTask.ErrorWhileCopying.Warning", source.toString(), target.toString(),
                e.getMessage()), e);
    }
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static Path write(Path path, Iterable<? extends CharSequence> lines, OpenOption... options) {
    if (options.length == 0) {
        options = new OpenOption[] { CREATE_NEW };
    }/*w  ww  . j  a va2 s . co m*/
    try {
        File parent = path.getParent().toFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        return path.toString().endsWith(".gz") ? GZIPFiles.write(path, lines, UTF_8, options)
                : path.toString().endsWith(".bz2") ? BZIP2Files.write(path, lines, UTF_8, options)
                        : Files.write(path, lines, UTF_8, options);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static Path write(Path path, Stream<?> lines, Charset cs, OpenOption... options) {
    if (options.length == 0) {
        options = new OpenOption[] { CREATE_NEW };
    }/*  w  w w.j  a  v a 2  s . co  m*/
    Objects.requireNonNull(lines);
    CharsetEncoder encoder = cs.newEncoder();
    try {
        OutputStream out = newOutputStream(path, options);
        if (path.toString().endsWith(".gz")) {
            out = new GZIPOutputStream(out);
        } else if (path.toString().endsWith(".bz2")) {
            out = new BZip2CompressorOutputStream(out);
        }
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoder), BUFFER_SIZE)) {
            lines.forEach(line -> {
                try {
                    writer.append(line.toString());
                    writer.newLine();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return path;
}

From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java

static void rethrowRemoteException(RemoteException e, Path p1, Path p2) throws IOException {
    switch (e.getClassName()) {
    case "org.apache.hadoop.fs.PathIsNotEmptyDirectoryException":
        throw new DirectoryNotEmptyException(p1.toString());

    case "org.apache.hadoop.fs.PathExistsException":
    case "org.apache.hadoop.fs.FileAlreadyExistsException":
        throw new FileAlreadyExistsException(Objects.toString(p1), Objects.toString(p2),
                e.getLocalizedMessage());

    case "org.apache.hadoop.fs.PathPermissionException":
    case "org.apache.hadoop.fs.PathAccessDeniedException":
        throw new AccessDeniedException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.ParentNotDirectoryException":
    case "org.apache.hadoop.fs.DirectoryListingStartAfterNotFoundException":
    case "org.apache.hadoop.fs.PathIsNotDirectoryException":
        throw new NotDirectoryException(Objects.toString(p1));

    case "org.apache.hadoop.fs.PathIsDirectoryException":
    case "org.apache.hadoop.fs.InvalidPathException":
    case "org.apache.hadoop.fs.PathNotFoundException":
        throw new NoSuchFileException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.UnresolvedLinkException":
        throw new NotLinkException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.PathIOException":
    case "org.apache.hadoop.fs.ChecksumException":
    case "org.apache.hadoop.fs.InvalidRequestException":
    case "org.apache.hadoop.fs.UnsupportedFileSystemException":
    case "org.apache.hadoop.fs.ZeroCopyUnavailableException":

    }//from w w  w.  jav a2  s.c  o  m

    throw new IOException(e.getLocalizedMessage(), e);
}

From source file:gedi.util.FileUtils.java

public static String getExtension(Path f) {
    String path = f.toString();
    return getExtension(path);
}

From source file:gedi.util.FileUtils.java

public static String getFullNameWithoutExtension(Path f) {
    String path = f.toString();
    return getFullNameWithoutExtension(path);
}

From source file:ch.rasc.edsutil.optimizer.WebResourceProcessor.java

private static String changeImageUrls(String contextPath, String cssSourceCode, String cssPath) {
    Matcher matcher = CSS_URL_PATTERN.matcher(cssSourceCode);
    StringBuffer sb = new StringBuffer();

    Path basePath = Paths.get(contextPath + cssPath);

    while (matcher.find()) {
        String url = matcher.group(2);
        url = url.trim();//from   w  ww .ja v a  2 s.  c o  m
        if (url.equals("#default#VML") || url.startsWith("data:")) {
            continue;
        }
        Path pa = basePath.resolveSibling(url).normalize();
        matcher.appendReplacement(sb, "$1" + pa.toString().replace("\\", "/") + "$3$4");
    }
    matcher.appendTail(sb);
    return sb.toString();
}

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

private static <T extends ConfProvider> T loadParameters(Path path, Class<T> clazz, T existingInstance)
        throws Exception {
    T params = existingInstance != null ? existingInstance : (T) clazz.newInstance();

    if (params.hasChanged()) {
        log.trace("Loading {} from {}", clazz.getSimpleName(), path);

        params.load(path.toString());
    }//from   ww  w .  java 2  s  .  c om

    return params;
}

From source file:com.excelsiorjet.api.util.Utils.java

public static void copyDirectory(Path source, Path target) throws IOException {
    Files.walkFileTree(source, new FileVisitor<Path>() {

        @Override//from   w  w w.  j a va 2s.  c  o  m
        public FileVisitResult preVisitDirectory(Path subfolder, BasicFileAttributes attrs) throws IOException {
            Files.createDirectories(target.resolve(source.relativize(subfolder)));
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException {
            Path targetFile = target.resolve(source.relativize(sourceFile));
            copyFile(sourceFile, targetFile);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path sourceFile, IOException e) throws IOException {
            throw new IOException(Txt.s("Utils.CannotCopyFile.Error", sourceFile.toString(), e.getMessage()),
                    e);
        }

        @Override
        public FileVisitResult postVisitDirectory(Path source, IOException ioe) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    });
}