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:com.fizzed.blaze.kotlin.BlazeKotlinEngineTest.java

@BeforeClass
static public void clearCache() throws IOException {
    Context context = new ContextImpl(null, Paths.get(System.getProperty("user.home")), null, null);
    Path classesDir = ConfigHelper.userBlazeEngineDir(context, "kotlin");
    FileUtils.deleteDirectory(classesDir.toFile());
}

From source file:org.trustedanalytics.utils.hdfs.LocalConfigTests.java

@BeforeClass
public static void initializeTmpFolder() throws IOException {
    // we use relative path as it seems to be harder case
    DESTINATION_PATH = Paths.get("local_hdfs_tests_folder_" + randomString());
    System.setProperty(FOLDER_PROPERTY, DESTINATION_PATH.toString());
}

From source file:oz.hadoop.yarn.api.utils.MiniClusterUtils.java

public static void startMiniCluster() {
    try {/*from w w w. j ava 2  s  .  co  m*/
        semaphore.acquire();
    } catch (InterruptedException e) {
        throw new IllegalStateException("Acquisition of semaphore is interrupted. Exiting");
    }
    if (clusterLauncher != null) {
        throw new IllegalStateException("MiniClustrer is currently running");
    }
    File file = new File("");
    Path path = Paths.get(file.getAbsolutePath());

    Path parentPath = path.getParent();

    File clusterConfiguration = new File(parentPath + "/yarn-test-cluster/src/main/resources");
    Assert.isTrue(clusterConfiguration.exists());
    ConfigUtils.addToClasspath(clusterConfiguration);

    File miniClusterExe = new File(
            parentPath.toString() + "/yarn-test-cluster/build/install/yarn-test-cluster/bin/yarn-test-cluster");
    System.out.println(miniClusterExe.getAbsolutePath());
    if (!miniClusterExe.exists()) {
        logger.info("BUILDING MINI_CLUSTER");
        CommandProcessLauncher buildLauncher = new CommandProcessLauncher(
                path.toString() + "/build-mini-cluster");
        buildLauncher.launch();
    }
    Assert.isTrue(miniClusterExe.exists(), "Failed to find mini-cluster executable");
    clusterLauncher = new CommandProcessLauncher(miniClusterExe.getAbsolutePath());
    executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            logger.info("STARTING MINI_CLUSTER");
            clusterLauncher.launch();
            System.out.println("EXITING>>>>>>>>>");
        }
    });
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:io.github.retz.executor.FileManager.java

static void fetchPersistentFiles(List<String> files, String destination, boolean trustPVFiles)
        throws IOException {
    for (String file : files) {
        java.nio.file.Path path = Paths.get(file).getFileName();
        if (path == null) {
            throw new FileSystemException(destination);
        }/* www .j a v  a 2s .com*/
        File f = new File(FilenameUtils.concat(destination, path.toString()));
        LOG.info("Downloading: {} as {}", file, f);
        if (f.exists()) {
            LOG.debug("File already exists: {}", f);
            if (!trustPVFiles) {
                try {
                    boolean needsDecompression = needsDecompression(f, destination);
                    if (needsDecompression) {
                        decompress(f, destination);
                    } else {
                        LOG.info("File {} was correctly decompressed before. Skipping decompression.", file);
                    }
                } catch (ArchiveException e) {
                    LOG.error("ArchiveException on {}: {}", f, e.getMessage());
                    e.printStackTrace();
                }
            }
        } else if (file.startsWith("http")) {
            fetchHTTPFile(file, destination);
            decompress(f, destination);
        } else if (file.startsWith("hdfs://")) {
            fetchHDFSFile(file, destination);
            decompress(f, destination);
        } else if (file.startsWith("maprfs://")) {
            fetchHDFSFile(file, destination);
            decompress(f, destination);
        } else {
            LOG.error("Invalid URL scheme: {}", file);
        }
    }
}

From source file:com.cisco.cta.taxii.adapter.ConfigTaskTest.java

@Test
public void createsConfigDir() throws Exception {
    Path configDir = Paths.get("target/config");
    FileUtils.deleteDirectory(configDir.toFile());
    ConfigTask cfTask = new ConfigTask(configDir.toString());
    cfTask.run();//from w  ww  . jav  a 2 s.com

    assertTrue(Files.exists(configDir));
    assertTrue(Files.exists(Paths.get(configDir.toString(), "application.yml")));
    assertTrue(Files.exists(Paths.get(configDir.toString(), "logback.xml")));
    assertTrue(Files.exists(Paths.get(configDir.toString(), "stix2cef.xsl")));
    assertTrue(Files.exists(Paths.get(configDir.toString(), "stix2splunk.xsl")));
    assertTrue(Files.exists(Paths.get(configDir.toString(), "stix2stix.xsl")));
    assertTrue(Files.exists(Paths.get(configDir.toString(), "taxii-response.xsl")));

}

From source file:sonata.kernel.vimadaptor.wrapper.openstack.javastackclient.JavaStackUtils.java

public static String readFile(String filePath) throws IOException {
    return new String(Files.readAllBytes(Paths.get(filePath)));
}

From source file:indexer.DocumentIndexerStrategy.java

public DocumentIndexerStrategy(String indexDirectory) throws IOException {
    dir = FSDirectory.open(Paths.get(indexDirectory));
    log = LogFactory.getLog(getClass());
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        try {/*w  ww . j  a  va 2 s .com*/
            log.info("Closing index writer.");
            getWriter().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }));
}

From source file:its.tools.SonarlintDaemon.java

private static String artifactVersion() {
    if (artifactVersion == null) {
        try {//w ww .  j a va  2  s .  c o  m
            for (String l : Files.readAllLines(Paths.get("pom.xml"), StandardCharsets.UTF_8)) {
                String lineTrimmed = l.trim();
                if (lineTrimmed.startsWith("<version>")) {
                    artifactVersion = lineTrimmed.substring("<version>".length(),
                            lineTrimmed.length() - "</version>".length());
                    break;
                }
            }
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
    return artifactVersion;
}

From source file:com.microsoft.azurebatch.jenkins.utils.ZipHelper.java

/**
 * Unzip all zip files in a folder/* w w  w . java  2  s.  com*/
 * @param srcFolderPath source folder
 * @param outputFolderPath output folder
 * @throws IOException
 */
public static void unzipFolder(String srcFolderPath, String outputFolderPath) throws IOException {
    File srcFolder = new File(srcFolderPath);
    if (!srcFolder.exists()) {
        return;
    }

    if (!Utils.dirExists(outputFolderPath)) {
        Files.createDirectory(Paths.get(outputFolderPath));
    }

    File[] files = srcFolder.listFiles();
    if (files != null) {
        for (File file : files) {
            unzipFile(file, outputFolderPath);
        }
    }
}

From source file:audiomanagershell.commands.PlayCommand.java

@Override
public void execute() throws CommandException, IOException {
    String OS = System.getProperty("os.name").toLowerCase();
    Path file;//from  www . j  ava2 s .  c o m
    if (OS.equals("windows"))
        file = Paths.get(this.pathRef.toString() + "\\" + this.arg);
    else
        file = Paths.get(this.pathRef.toString() + "/" + this.arg);
    String fileName = file.getFileName().toString();
    List<String> acceptedExtensions = Arrays.asList("wav", "mp3", "flac", "mp4");
    //Get the extension of the file
    String extension = FilenameUtils.getExtension(fileName);
    if (Files.isRegularFile(file) && Files.isReadable(file)) {
        if (acceptedExtensions.contains(extension)) {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file.toFile());
            System.out.printf("The file %s will open shortly...\n", fileName);
        } else {
            throw new NotAudioFileException(fileName);
        }
    } else {
        throw new CommandException(file.toString() + " not a file or can't read");
    }
}