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:berlin.iconn.persistence.InOutOperations.java

public static float[][] loadSimpleWeights(File file) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file.toPath()));
    float[][] weights = (float[][]) ois.readObject();
    ois.close();/*from   w w w .  j a  va2  s . c  o  m*/
    return weights;
}

From source file:com.netease.hearttouch.hthotfix.patch.PatchSoHelper.java

/**
 * ??so?hash//from ww w .  j  a  v a2s  .c  o m
 * @param project
 * @param soDir
 */
public static void hashSoFiles(final Project project, ArrayList<String> soDir) {
    final HashMap<String, String> hashMap = new HashMap<>();
    final String projectDir = project.getProjectDir().toString();

    try {
        for (String dirPath : soDir) {
            File dir = new File(dirPath);
            if (!dir.exists())
                continue;
            Files.walkFileTree(dir.toPath(), new SopathVisitor() {
                @Override
                protected void visitSo(Path path, byte[] bytecode) {
                    String soFilePath = path.toString();
                    soFilePath = soFilePath.replace(projectDir, "");
                    String sha1Hex = DigestUtils.shaHex(bytecode);
                    hashMap.put(soFilePath, sha1Hex);
                }
            });
        }

        if (!hashMap.isEmpty()) {
            isSoExist = true;

            HashFileHelper.generate(hashMap, Constants.getHotfixPath(project, Constants.HOTFIX_SO_HASH),
                    project.getLogger(), "PatchSoHelper generate error");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:jease.site.Streams.java

/**
 * Write given file to response./*from w  w  w . j a v  a 2 s .com*/
 * 
 * If the given content type denotes a browser supported image, the image
 * will be automatically scaled if either "scale" is present as request
 * paramter or JEASE_IMAGE_LIMIT is set in Registry.
 */
public static void write(HttpServletRequest request, HttpServletResponse response, File file,
        String contentType) throws IOException {
    if (Images.isBrowserCompatible(contentType)) {
        int scale = NumberUtils.toInt(request.getParameter("scale"));
        if (scale > 0) {
            java.io.File scaledImage = Images.scale(file, scale);
            scaledImage.deleteOnExit();
            response.setContentType(contentType);
            response.setContentLength((int) scaledImage.length());
            Files.copy(scaledImage.toPath(), response.getOutputStream());
            return;
        }
        int limit = NumberUtils.toInt(Registry.getParameter(Names.JEASE_IMAGE_LIMIT));
        if (limit > 0) {
            java.io.File scaledImage = Images.limit(file, limit);
            scaledImage.deleteOnExit();
            response.setContentType(contentType);
            response.setContentLength((int) scaledImage.length());
            Files.copy(scaledImage.toPath(), response.getOutputStream());
            return;
        }

    }
    response.setContentType(contentType);
    response.setContentLength((int) file.length());
    Files.copy(file.toPath(), response.getOutputStream());
}

From source file:net.arccotangent.pacchat.filesystem.KeyManager.java

public static PublicKey loadKeyByIP(String ip_address) {
    km_log.i("Loading public key for " + ip_address);
    try {//from  w  ww .  j  a v a 2s.  c  om
        File pubFile = new File(installationPath + File.separator + ip_address + ".pub");

        byte[] pubEncoded = Files.readAllBytes(pubFile.toPath());
        X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(Base64.decodeBase64(pubEncoded));

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        return keyFactory.generatePublic(pubSpec);
    } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException e) {
        km_log.e("Error while loading public key for " + ip_address + "!");
        e.printStackTrace();
    }
    return null;
}

From source file:gov.nist.appvet.shared.FileUtil.java

public static synchronized boolean copyFile(File sourceFile, File destFile) {
    if (sourceFile == null || !sourceFile.exists() || destFile == null) {
        return false;
    }/*from   w ww  .j  a  v  a2s  .c o  m*/
    try {
        Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (final IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:es.upv.grycap.coreutils.fiber.test.mockserver.ObjectResponseValidator.java

public static void validateXml(final File file, final String expectedId)
        throws SAXException, IOException, ParserConfigurationException, XPathExpressionException {
    final String objectId = readObjectIdFromXml(new String(readAllBytes(file.toPath())));
    assertThat("Object Id coincides with expected", objectId,
            allOf(notNullValue(), not(equalTo("")), equalTo(expectedId)));
}

From source file:eu.interedition.collatex.tools.CollationPipe.java

private static PrintWriter argumentToOutput(String arg, Charset outputCharset)
        throws ParseException, IOException {
    if ("-".equals(arg)) {
        return new PrintWriter(new OutputStreamWriter(System.out, outputCharset));
    }//w ww. j a  v  a  2 s.  c  o m

    final File outFile = new File(arg);
    try {
        return new PrintWriter(Files.newBufferedWriter(outFile.toPath(), outputCharset));
    } catch (FileNotFoundException e) {
        throw new ParseException("Output file '" + outFile + "' not found");
    }
}

From source file:gov.nist.appvet.tool.sigverifier.util.FileUtil.java

public static boolean copyFile(File sourceFile, File destFile) {
    if (sourceFile == null || !sourceFile.exists() || destFile == null) {
        return false;
    }//w  w  w  .  j  a  va2 s . co  m
    try {
        Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (final IOException e) {
        log.error(e.toString());
        return false;
    }
    return true;
}

From source file:by.creepid.docsreporter.context.DocContextProcessorTest.java

private static byte[] getImage(String path) {
    File fi = new File(path);

    try {/*from   w w w.  java 2  s.  c o m*/
        return Files.readAllBytes(fi.toPath());
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    throw new RuntimeException("Cannot set the photo");
}

From source file:gov.nist.appvet.shared.FileUtil.java

public static synchronized boolean copyFile(String sourceFilePath, String destFilePath) {
    if (sourceFilePath == null || destFilePath == null) {
        return false;
    }/*from w ww .  ja  v a  2  s. c om*/
    File sourceFile = new File(sourceFilePath);
    if (!sourceFile.exists()) {
        return false;
    }
    File destFile = new File(destFilePath);
    try {
        Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (final IOException e) {
        log.error(e.getMessage());
        return false;
    } finally {
        sourceFile = null;
        destFile = null;
    }
    return true;
}