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:de.tuberlin.uebb.jbop.access.ClassAccessor.java

/**
 * Stores a classfile for the given Classdescriptor.
 * //from   w  w  w  .  ja  v  a 2  s  .c  om
 * The Class for the File could be loaded with the ClassLoader proposed by this
 * Class ({@link #getClassloader()}) or any suitable ClassLoader using the returned
 * Path of the Classfile.
 * 
 * @param classDescriptor
 *          the class descriptor
 * @return the path of the written File
 * @throws JBOPClassException
 *           the jBOP class exception
 */
public static Path store(final ClassDescriptor classDescriptor) throws JBOPClassException {

    final Path packageDir = Paths.get(TMP_DIR.toString(), classDescriptor.getPackageDir());
    final Path classFile = Paths.get(packageDir.toString(), classDescriptor.getSimpleName() + ".class");
    try {
        Files.createDirectories(packageDir);
        Files.write(classFile, classDescriptor.getClassData(), StandardOpenOption.CREATE,
                StandardOpenOption.WRITE);
        classDescriptor.setFile(classFile.toString());
        return classFile;
    } catch (final IOException e) {
        throw new JBOPClassException(
                "Data of Class " + classDescriptor.getName() + " could not be written to file.", e);
    }
}

From source file:com.expedia.tesla.compiler.Util.java

/**
 * Expand glob file patterns to path strings. Any path element that is not a glob pattern will be keep as it is.
 * /*from  w  ww  .j  ava  2  s . co m*/
 * @param pathOrPatterns
 *       glob patterns.
 * 
 * @return
 *       The expanded paths.
 * 
 * @throws IOException
 *       On IO errors.
 */
public static Collection<String> expandWildcard(Collection<String> pathOrPatterns) throws IOException {
    final List<String> files = new ArrayList<String>();
    final List<PathMatcher> matchers = new ArrayList<PathMatcher>();
    for (String pattern : pathOrPatterns) {
        if (pattern.contains("*") || pattern.contains("?")) {
            PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
            matchers.add(matcher);
        } else {
            files.add(pattern);
        }
    }

    if (!matchers.isEmpty()) {
        Files.walkFileTree(new File(System.getProperty("user.dir")).toPath(), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
                for (PathMatcher matcher : matchers) {
                    if (matcher.matches(file)) {
                        files.add(file.toString());
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        });
    }

    return files;
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java

/**
 * @param fileName the file name//from   w  w  w.j a  v  a  2  s . c  om
 * @return the metadata for the given file.
 * @throws Exception if the metadata cannot be loaded
 */
public static ConfigurationPartMetadata getMetadata(Path fileName) throws Exception {
    File file = new File(fileName.toString() + METADATA_SUFFIX);
    try (InputStream in = new FileInputStream(file)) {
        return ConfigurationPartMetadata.read(in);
    }
}

From source file:cruise.umple.umpr.core.consistent.Consistents.java

/**
 * Builds an {@link ImportRepositorySet} from the runtime data produced by the {@link ConsoleMain} using 
 * {@link ConsistentsBuilder}.  //w  ww .  jav a2  s .co  m
 * 
 * @param outputFolder The location the repository lives. 
 * @param allData {@link List} of {@link ImportRuntimeData} to map into new the consistent data structures. 
 * @return Non-{@code null} instance
 */
public static ImportRepositorySet buildImportRepositorySet(final Path outputFolder, final Path srcFolder,
        final Iterable<? extends ImportFSM> allData) {

    final Multimap<Repository, ? extends ImportFSM> dataByRepo = Multimaps.index(allData,
            ImportFSM::getRepository);

    final ConsistentsBuilder cbld = CONSISTENTS_FACTORY.create(outputFolder, srcFolder);
    dataByRepo.asMap().entrySet().forEach(entry -> {
        final Repository key = entry.getKey();
        final ConsistentRepositoryBuilder repoBld = cbld.withRepository(key);

        entry.getValue().forEach(data -> {
            final Path outpath = data.getOutputPath().getFileName();
            if (data.isSuccessful()) {
                repoBld.addSuccessFile(outpath.toString(), data.getImportType(), data.getAttribLoc());
            } else {
                repoBld.addFailedFile(outpath.toString(), data.getImportType(), data.getAttribLoc(),
                        data.getState(), data.getFailure().get());
            }
        });

        repoBld.withCalculatedSuccessRate();
    });

    return cbld.getRepositorySet();
}

From source file:com.joyent.manta.client.MantaClientAuthenticationChangeIT.java

private static void swapKeyLocation(final AuthAwareConfigContext config, final boolean fromPathToContent)
        throws IOException {

    if (fromPathToContent) {
        // move key to MANTA_KEY_CONTENT
        final String keyContent = FileUtils.readFileToString(new File(config.getMantaKeyPath()),
                StandardCharsets.UTF_8);
        config.setMantaKeyPath(null);/*w ww.  jav  a 2 s  .  co m*/
        config.setPrivateKeyContent(keyContent);
        return;
    }

    // move key to MANTA_KEY_FILE
    final Path tempKey = Paths.get("/Users/tomascelaya/sandbox/");
    FileUtils.forceDeleteOnExit(tempKey.toFile());
    FileUtils.writeStringToFile(tempKey.toFile(), config.getPrivateKeyContent(), StandardCharsets.UTF_8);
    config.setPrivateKeyContent(null);
    config.setMantaKeyPath(tempKey.toString());
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java

/**
 * Saves the expiration date for the given file.
 * @param fileName the file/*  w ww.  j a v a2  s  .  co m*/
 * @param metadata the metadata
 * @throws Exception if an error occurs
 */
public static final void saveMetadata(Path fileName, ConfigurationPartMetadata metadata) throws Exception {
    AtomicSave.execute(fileName.toString() + METADATA_SUFFIX, "expires", metadata.toByteArray(),
            StandardCopyOption.ATOMIC_MOVE);
}

From source file:Main.java

/**
 * Loads the object from the file./* w w w.j  a v  a 2s.c o m*/
 *
 * @param <T> the object type.
 * @param path the XML file.
 * @param clazz the class of the object.
 * @return the corresponding object.
 */
public static <T> T loadObject(Path path, Class<T> clazz) {
    T result;
    if (path == null || clazz == null) {
        throw new RuntimeException("The path to file or class is null!");
    }

    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        result = (T) jaxbUnmarshaller.unmarshal(path.toFile());
    } catch (Exception ex) {
        throw new RuntimeException("Error loading the xml from path " + path.toString(), ex);
    }
    return result;
}

From source file:Main.java

public static Document CreateDocument(Path xml, Path xsd)
        throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//from w ww  .j ava  2  s  .  c  o  m
    factory.setNamespaceAware(true);
    factory.setIgnoringComments(true);
    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
            "http://www.w3.org/2001/XMLSchema");
    if (xsd != null)
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", xsd.toString());
    return factory.newDocumentBuilder().parse(xml.toString());
}

From source file:Main.java

public static Document CreateDocument(Path xml, Path xsd)
        throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*from w  w w .  j  a  v a 2s  .co  m*/
    factory.setNamespaceAware(true);
    factory.setIgnoringComments(true);
    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
            "http://www.w3.org/2001/XMLSchema");
    if (xsd != null) {
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", xsd.toString());
    }
    return factory.newDocumentBuilder().parse(xml.toString());
}

From source file:de.monticore.io.paths.IterablePath.java

/**
 * Encapsulates creation of a {@link Stream} of {@link Path}s for a given start {@link Path}.
 * /*from   w w  w  . j  a  va  2 s  .c o m*/
 * @param path
 * @return
 */
protected static Stream<Path> walkFileTree(Path path) {
    if (path.toFile().exists()) {
        try {
            return Files.walk(path);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        Log.warn("0xA4074 The supplied path " + path.toString() + " does not exist.");
        return Stream.empty();
    }
}