Example usage for java.io File toPath

List of usage examples for java.io File toPath

Introduction

In this page you can find the example usage for java.io File toPath.

Prototype

public Path toPath() 

Source Link

Document

Returns a Path java.nio.file.Path object constructed from this abstract path.

Usage

From source file:com.fizzed.rocker.compiler.RockerUtil.java

static public String md5(File f) throws IOException {
    try {//from w  w w .  j a v  a2s .co  m
        byte[] b = Files.readAllBytes(f.toPath());
        byte[] hash = MessageDigest.getInstance("MD5").digest(b);
        return byteArrayToHex(hash);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e.getMessage(), e);
    }
}

From source file:com.tripod.solr.util.EmbeddedSolrServerFactory.java

/**
 * @param solrHome the Solr home directory to use
 * @param configSetHome the directory containing config sets
 * @param coreName the name of the core, must have a matching directory in configHome
 * @param cleanSolrHome if true the directory for solrHome will be deleted and re-created if it already exists
 * @return an EmbeddedSolrServer with a core created for the given coreName
 *//*w  w  w .  jav  a 2s  . c o m*/
public static SolrClient create(final String solrHome, final String configSetHome, final String coreName,
        final boolean cleanSolrHome) throws IOException, SolrServerException {

    final File solrHomeDir = new File(solrHome);
    if (solrHomeDir.exists()) {
        FileUtils.deleteDirectory(solrHomeDir);
        solrHomeDir.mkdirs();
    } else {
        solrHomeDir.mkdirs();
    }

    final SolrResourceLoader loader = new SolrResourceLoader(solrHomeDir.toPath());
    final Path configSetPath = Paths.get(configSetHome).toAbsolutePath();

    final NodeConfig config = new NodeConfig.NodeConfigBuilder("embeddedSolrServerNode", loader)
            .setConfigSetBaseDirectory(configSetPath.toString()).build();

    final EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(config, coreName);

    final CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
    createRequest.setCoreName(coreName);
    createRequest.setConfigSet(coreName);
    embeddedSolrServer.request(createRequest);

    return embeddedSolrServer;
}

From source file:com.ibm.streamsx.topology.internal.context.remote.ZippedToolkitRemoteContext.java

private static Path pack(final Path folder, JsonObject graph, String tkName)
        throws IOException, URISyntaxException {
    String namespace = splAppNamespace(graph);
    String name = splAppName(graph);

    Path zipFilePath = Paths.get(folder.toAbsolutePath().toString() + ".zip");
    String workingDir = zipFilePath.getParent().toString();

    Path topologyToolkit = TkInfo.getTopologyToolkitRoot().getAbsoluteFile().toPath();

    // Paths to copy into the toolkit
    Map<Path, String> paths = new HashMap<>();

    // tkManifest is the list of toolkits contained in the archive
    try (PrintWriter tkManifest = new PrintWriter("manifest_tk.txt", "UTF-8")) {
        tkManifest.println(tkName);/*  ww  w .  java 2 s .co  m*/
        tkManifest.println("com.ibm.streamsx.topology");

        JsonObject configSpl = object(graph, CONFIG, "spl");
        if (configSpl != null) {
            objectArray(configSpl, "toolkits", tk -> {
                File tkRoot = new File(jstring(tk, "root"));
                String tkRootName = tkRoot.getName();
                tkManifest.println(tkRootName);
                paths.put(tkRoot.toPath(), tkRootName);
            });
        }
    }

    // mainComposite is a string of the namespace and the main composite.
    // This is used by the Makefile
    try (PrintWriter mainComposite = new PrintWriter("main_composite.txt", "UTF-8")) {
        mainComposite.print(namespace + "::" + name);
    }

    Path manifest = Paths.get(workingDir, "manifest_tk.txt");
    Path mainComp = Paths.get(workingDir, "main_composite.txt");
    Path makefile = topologyToolkit
            .resolve(Paths.get("opt", "python", "templates", "common", "Makefile.template"));

    paths.put(topologyToolkit, topologyToolkit.getFileName().toString());
    paths.put(manifest, "manifest_tk.txt");
    paths.put(mainComp, "main_composite.txt");
    paths.put(makefile, "Makefile");
    paths.put(folder, folder.getFileName().toString());

    addAllToZippedArchive(paths, zipFilePath);
    manifest.toFile().delete();
    mainComp.toFile().delete();

    return zipFilePath;
}

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

public static Path write(File file, Stream<?> lines, OpenOption... options) {
    return write(file.toPath(), lines, options);
}

From source file:com.seleniumtests.util.logging.SeleniumRobotLogger.java

/**
 * Clean result directories/*from   www .j a  va  2 s.  c  om*/
 * Delete the directory that will be used to write these test results
 * Delete also directories in "test-output" which are older than 300 minutes. Especially useful when test is requested to write result
 * to a sub-directory of test-output with timestamp (for example). Without this mechanism, results would never be cleaned
 */
private static void cleanResults() {
    // clean output dir
    try {
        FileUtils.deleteDirectory(new File(outputDirectory));
        WaitHelper.waitForSeconds(1);
    } catch (IOException e) {
        // do nothing
    }

    new File(outputDirectory).mkdirs();
    WaitHelper.waitForSeconds(1);

    if (new File(defaultOutputDirectory).exists()) {
        for (File directory : new File(defaultOutputDirectory).listFiles(file -> file.isDirectory())) {
            try {
                if (Files.readAttributes(directory.toPath(), BasicFileAttributes.class).lastAccessTime()
                        .toInstant().atZone(ZoneOffset.UTC).toLocalTime().isBefore(ZonedDateTime.now()
                                .minusMinutes(300).withZoneSameInstant(ZoneOffset.UTC).toLocalTime())) {
                    FileUtils.deleteDirectory(directory);
                }
            } catch (IOException e) {
            }

        }
    }
}

From source file:de.alpharogroup.crypto.key.reader.PrivateKeyReader.java

/**
 * Read private key.//  w w  w.j  a  va 2s  .co  m
 *
 * @param file
 *            the file
 * @param provider
 *            the security provider
 * @return the private key
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws NoSuchAlgorithmException
 *             is thrown if instantiation of the cypher object fails.
 * @throws InvalidKeySpecException
 *             is thrown if generation of the SecretKey object fails.
 * @throws NoSuchProviderException
 *             is thrown if the specified provider is not registered in the security provider
 *             list.
 */
public static PrivateKey readPrivateKey(final File file, final String provider)
        throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
    final byte[] keyBytes = Files.readAllBytes(file.toPath());
    return readPrivateKey(keyBytes, provider);
}

From source file:de.alpharogroup.crypto.key.KeyExtensions.java

/**
 * reads a public key from a file./*from w w  w  . j  a v a 2  s .com*/
 *
 * @param file
 *            the file
 * @param securityProvider
 *            the security provider
 * @return the public key
 * @throws Exception
 *             is thrown if if a security error occur
 */
public static PublicKey readPemPublicKey(final File file, final SecurityProvider securityProvider)
        throws Exception {
    final byte[] keyBytes = Files.readAllBytes(file.toPath());
    final String publicKeyAsString = new String(keyBytes).replace(BEGIN_PUBLIC_KEY_PREFIX, "")
            .replace(END_PUBLIC_KEY_SUFFIX, "");
    final byte[] decoded = Base64.decodeBase64(publicKeyAsString);
    return readPublicKey(decoded, securityProvider);
}

From source file:de.alpharogroup.crypto.key.KeyExtensions.java

/**
 * Read pem private key.//w w  w .j av a2 s .c om
 *
 * @param file
 *            the file
 * @param securityProvider
 *            the security provider
 * @return the private key
 * @throws Exception
 *             is thrown if if a security error occur
 */
public static PrivateKey readPemPrivateKey(final File file, final SecurityProvider securityProvider)
        throws Exception {
    final byte[] keyBytes = Files.readAllBytes(file.toPath());

    final String privateKeyAsString = new String(keyBytes).replace(BEGIN_RSA_PRIVATE_KEY_PREFIX, "")
            .replace(END_RSA_PRIVATE_KEY_SUFFIX, "").trim();

    final byte[] decoded = new Base64().decode(privateKeyAsString);

    return readPrivateKey(decoded, securityProvider);
}

From source file:eu.eubrazilcc.lvl.service.io.DatasetWriter.java

public static void unsetDataset(final Dataset dataset) {
    File outfile = null;
    checkArgument(dataset != null && (outfile = dataset.getOutfile()) != null,
            "Uninitialized of invalid dataset");
    if (isRegularFile(outfile.toPath(), NOFOLLOW_LINKS)) {
        deleteQuietly(outfile);// w w  w  .j  a v  a2  s. co  m
    }
    final File parent = outfile.getParentFile();
    if (isDirectory(parent.toPath(), NOFOLLOW_LINKS)) {
        try {
            delete(parent.toPath());
        } catch (DirectoryNotEmptyException e) {
            LOGGER.warn("The directory is not empty, so was not removed: " + parent.getAbsolutePath());
        } catch (IOException e) {
            LOGGER.error("Failed to remove directory: " + parent.getAbsolutePath(), e);
        }
    }
    LOGGER.trace("Public link was removed: " + outfile.getAbsolutePath());
}

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

public static Path write(File file, Iterable<? extends CharSequence> lines, OpenOption... options) {
    return write(file.toPath(), lines, options);
}