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:br.com.thiaguten.archive.AbstractArchive.java

public static Path removeExtension(Path file) {
    String str = file.toString();
    int index = str.lastIndexOf('.');
    if (index > 0) {
        file = Paths.get(str.substring(0, index));
    }/*w ww . jav  a2  s . co  m*/
    return file;
}

From source file:com.kixeye.chassis.bootstrap.TestUtils.java

@SuppressWarnings("unchecked")
public static void writePropertiesToFile(String path, Set<Path> filesCreated,
        SimpleEntry<String, String>... entries) {
    Properties properties = new Properties();
    for (SimpleEntry<String, String> entry : entries) {
        properties.put(entry.getKey(), entry.getValue());
    }/*from   ww  w  .j a va 2  s .  co m*/
    Path p = Paths.get(SystemPropertyUtils.resolvePlaceholders(path));
    try (OutputStream os = createFile(p.toString())) {
        properties.store(os, "test properties");
        filesCreated.add(p);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:base64test.Base64Test.java

public static String getFileType(Path filePath) {
    String fileType = "Undetermined";
    try {/*w ww .j  a v  a 2 s .c  o m*/
        fileType = Files.probeContentType(filePath);
    } catch (IOException ioE) {
        System.err.println(
                "ERROR: Unable to determine file type for " + filePath.toString() + " due to exception " + ioE);
    }

    return fileType;
}

From source file:de.sanandrew.mods.turretmod.registry.electrolytegen.ElectrolyteRegistry.java

private static boolean processJson(Path root, Path file) {
    if (!"json".equals(FilenameUtils.getExtension(file.toString()))
            || root.relativize(file).toString().startsWith("_")) {
        return true;
    }//from  www . j ava  2 s.c  o m

    try (BufferedReader reader = Files.newBufferedReader(file)) {
        JsonObject json = JsonUtils.fromJson(reader, JsonObject.class);

        if (json == null || json.isJsonNull()) {
            throw new JsonSyntaxException("Json cannot be null");
        }

        NonNullList<ItemStack> inputItems = JsonUtils.getItemStacks(json.get("electrolytes"));
        float effectiveness = JsonUtils.getFloatVal(json.get("effectiveness"));
        int ticksProcessing = JsonUtils.getIntVal(json.get("timeProcessing"));
        ItemStack trash = ItemStackUtils.getEmpty();
        ItemStack treasure = ItemStackUtils.getEmpty();

        JsonElement elem = json.get("trash");
        if (elem != null && !elem.isJsonNull()) {
            trash = JsonUtils.getItemStack(elem);
        }
        elem = json.get("treasure");
        if (elem != null && !elem.isJsonNull()) {
            treasure = JsonUtils.getItemStack(elem);
        }

        registerFuels(inputItems, effectiveness, ticksProcessing, trash, treasure);
    } catch (JsonParseException e) {
        TmrConstants.LOG.log(Level.ERROR,
                String.format("Parsing error loading electrolyte generator recipe from %s", file), e);
        return false;
    } catch (IOException e) {
        TmrConstants.LOG.log(Level.ERROR, String.format("Couldn't read recipe from %s", file), e);
        return false;
    }

    return true;
}

From source file:com.textocat.textokit.commons.consumer.XmiFileWriter.java

public static AnalysisEngineDescription createDescription(Path outputBasePath)
        throws ResourceInitializationException {
    return AnalysisEngineFactory.createEngineDescription(XmiFileWriter.class, PARAM_OUTPUT_BASE_PATH,
            outputBasePath.toString());
}

From source file:com.dangdang.ddframe.job.example.JavaLiteJobMain.java

private static String buildScriptCommandLine() throws IOException {
    if (System.getProperties().getProperty("os.name").contains("Windows")) {
        return Paths.get(JavaLiteJobMain.class.getResource("/script/demo.bat").getPath().substring(1))
                .toString();//from  ww  w.  ja  va2s  .c  om
    }
    Path result = Paths.get(JavaLiteJobMain.class.getResource("/script/demo.sh").getPath());
    Files.setPosixFilePermissions(result, PosixFilePermissions.fromString("rwxr-xr-x"));
    return result.toString();
}

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

/**
 * ??so?hash/*from w w w .  j  a v a 2  s . com*/
 * @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:fr.cnrs.sharp.reasoning.Harmonization.java

public static File harmonizeProv(File inputProv) throws IOException {
    Model inputGraph = FileManager.get().loadModel(inputProv.getAbsolutePath());
    Model harmonizedProv = harmonizeProv(inputGraph);

    Path pathInfProv = Files.createTempFile("PROV-inf-tgd-egd-", ".ttl");
    harmonizedProv.write(new FileWriter(pathInfProv.toFile()), "TTL");
    logger.info("PROV inferences file written to " + pathInfProv.toString());
    return pathInfProv.toFile();
}

From source file:com.playonlinux.filesystem.DirectoryWatcher.java

private static void validate(Path observedDirectory) {
    if (!Files.isDirectory(observedDirectory)) {
        throw new IllegalStateException(
                String.format("The file %s is not a valid directory", observedDirectory.toString()));
    }//w  w  w .ja  v a2s  .  co  m
}

From source file:edu.cwru.jpdg.Javac.java

/**
 * Takes the full package name of the java file to load from the
 * resources (see `Javac.load` for details). It uses `load` to get the
 * file and `javac` to compile it. It then loads up the classes using soot.
 *
 * @returns HashMap : package_name - JavaClass
 *//*w w  w  .j a v  a  2  s . co  m*/
public static HashMap<String, soot.SootClass> classes(String full_name) {
    String[] split = StringUtils.split(full_name, ".");
    String name = split[split.length - 1];
    String basedir = "/tmp";
    javac(basedir, name, load(full_name));
    HashMap<String, soot.SootClass> map = new HashMap<String, soot.SootClass>();

    String cp = System.getenv().get("JAVA_JARS");
    Path dir = Paths.get(cwd).resolve(basedir);
    Path build = dir.resolve("build");
    String base_dir = build.toString();
    List<String> dirs = new ArrayList<String>();
    dirs.add(base_dir);

    soot.Scene S = edu.cwru.jpdg.JPDG.runSoot(cp, dirs, new ArrayList<String>());
    for (soot.SootClass klass : S.getApplicationClasses()) {
        System.out.println(klass);
        map.put(klass.getName(), klass);
    }
    return map;
}