Example usage for java.nio.file Paths get

List of usage examples for java.nio.file Paths get

Introduction

In this page you can find the example usage for java.nio.file Paths get.

Prototype

public static Path get(URI uri) 

Source Link

Document

Converts the given URI to a Path object.

Usage

From source file:mpimp.assemblxweb.util.J5FileUtils.java

public static String encodeFileBase64(String filePath) throws Exception {
    Path path = Paths.get(filePath);
    String result = "";
    try {//  w w  w  .j  a  va  2  s . c o m
        byte[] content = Files.readAllBytes(path);
        result = Base64.encodeBase64String(content);
    } catch (IOException e) {
        String message = "Error while encoding file " + filePath + ". " + e.getMessage();
        throw new AssemblXException(message, J5FileUtils.class);
    }
    return result;
}

From source file:com.predic8.membrane.core.interceptor.apimanagement.ApiManagementConfigurationTest.java

@Test
public void testParseYaml() throws Exception {
    String source = new String(
            Files.readAllBytes(Paths
                    .get(System.getProperty("user.dir") + "\\src\\test\\resources\\apimanagement\\api.yaml")),
            Charset.defaultCharset());

    ApiManagementConfiguration conf = new ApiManagementConfiguration();
    conf.setLocation(source);// w w  w  . jav  a2 s  .c  o  m
    Map<String, Policy> policies = conf.getPolicies();
    for (Policy p : policies.values()) {
        System.out.println(p);
    }
    Map<String, Key> keys = conf.getKeys();
    for (Key k : keys.values()) {
        System.out.println(k);
    }

}

From source file:fi.johannes.kata.ocr.utils.files.CFileOperations.java

public static String fileContentToString(String filepath) throws IOException {
    Path p = Paths.get(filepath);
    byte[] contents = Files.readAllBytes(p);
    return new String(contents, StandardCharsets.UTF_8);
}

From source file:acromusashi.stream.resource.ResourceResolver.java

/**
 * Return target file path from resource's path.
 *
 * @param path resource's path/* w ww . j  a  va  2s  . c  o  m*/
 * @return File object
 */
public static File resolve(String path) {
    Class<?> callerClass = resolveCaller();
    URL url = callerClass.getResource(path);
    if (url == null) {
        return null;
    }

    File result;
    try {
        result = Paths.get(url.toURI()).toFile();
    } catch (URISyntaxException ex) {
        return null;
    }

    return result;
}

From source file:file.FileOperatorTest.java

public static List<Path> testWalkFile() throws Exception {
    List<Path> paths = Lists.newArrayList();
    long a = System.currentTimeMillis();
    Files.walkFileTree(Paths.get(ROOT_DIR), new FileVisitor<Path>() {
        @Override/* w w  w.j a va  2  s .  c o m*/
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            return FileVisitResult.CONTINUE;
        }

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

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    });
    long b = System.currentTimeMillis();
    System.out.println(":" + (b - a));
    return paths;
}

From source file:indexer.PDFDocument.java

@Override
public String getContents() {
    PDFTextExtractor extractor = new PDFTextExtractor();
    try {//from  w  w  w.j av  a 2s. c  om
        return extractor.extractText(Paths.get(path).toString());
    } catch (IOException e) {
        log.error("Error while extracting text from: " + getName());
    }
    return StringUtils.EMPTY;
}

From source file:com.curso.ejemplohinputfile.FileUploadBean.java

public String processFileUpload() throws IOException {
    Part uploadedFile = getFile();// ww  w  . j a  v  a 2s.c o  m
    final Path destination = Paths.get("c:/tmp/" + FilenameUtils.getName(getSubmittedFileName(uploadedFile)));
    //Con servlet 3.1
    //final Path destination = Paths.get("c:/tmp/"+ FilenameUtils.getName(uploadedFile.getSubmittedFileName()));
    InputStream bytes = null;
    if (null != uploadedFile) {
        bytes = uploadedFile.getInputStream(); //
        Files.copy(bytes, destination);
    }
    return "success";
}

From source file:com.nsn.squirrel.tab.utils.PathUtils.java

/**
 * Default path can be different for various OS
 * //from w  ww . ja v a  2  s.  c  om
 * @return default path
 */
public static Path getDefaultPath() {

    Path defaultPath = Paths.get(""); //$NON-NLS-1$
    if (SystemUtils.IS_OS_WINDOWS) {
        defaultPath = Paths.get("C:\\"); //$NON-NLS-1$
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        defaultPath = Paths.get(System.getenv().get("HOME")); //$NON-NLS-1$
    }
    return defaultPath;
}

From source file:com.sonar.maven.it.suite.AbstractMavenTest.java

protected static Version mojoVersion() {
    if (mojoVersion == null) {
        try {//from  w w w.  j a v a 2s.c  o m
            for (String line : Files.readAllLines(Paths.get("../pom.xml"), StandardCharsets.UTF_8)) {
                if (line.startsWith("  <version>")) {
                    String version = StringUtils.substringAfter(line, "<version>");
                    version = StringUtils.substringBefore(version, "</version>");
                    mojoVersion = Version.create(version);
                    return mojoVersion;
                }
            }
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        throw new IllegalStateException("Unable to find version of the Maven plugin to be used by ITs");
    }
    return mojoVersion;
}

From source file:ec.edu.chyc.manejopersonal.util.ServerUtils.java

/***
 *
 * @return Ruta del docroot de glassfish
 *//*from   w  w  w  . j  av a 2s  .com*/
public static Path getDocRootPath() {
    return Paths.get("").toAbsolutePath().getParent().resolve("docroot").normalize();
}