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:pinterestbackup.PINDownloader.java

private void populateFileMap(Path pathDir) {
    //Read all file in pathDir and store in the local hashmap
    this.localFiles.clear();

    if (pathDir != null) {
        try {//from  w ww . jav a  2 s  . c om
            DirectoryStream<Path> stream = Files.newDirectoryStream(pathDir);
            for (Path path : stream) {
                this.localFiles.put(path.toString(), Boolean.FALSE);
            }
        } catch (IOException ex) {
            Logger.getLogger(PinterestBackup.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:onl.area51.metoffice.metoffice.forecast.layer.ForecastImageLayerWS.java

protected HttpEntity sendLayer(String layerName, Request request) {
    Layer layer = forecastImageLayerService.getLayer(request.getAttribute(layerName));
    if (layer != null) {
        return new JsonEntity(Json.createObjectBuilder().add("name", layer.getName())
                .add("layerName", layer.getLayerName()).add("displayName", layer.getDisplayName())
                .add("defaultTime", layer.getDefaultTime()).add("format", layer.getFormat())
                // Array of timesteps
                .add("timestep", IntStream.of(layer.getTimestep()).mapToObj(Integer::valueOf).reduce(
                        Json.createArrayBuilder(), (a, i) -> a.add(i), Functions.writeOnceBinaryOperator()))
                // Map of timestep to actual image url
                .add("images", IntStream.of(layer.getTimestep()).mapToObj(Integer::valueOf)
                        .reduce(Json.createObjectBuilder(), (a, ts) -> {
                            Path p = forecastImageLayerService.getPath(layer, ts);
                            if (p != null) {
                                String ps = p.toString();
                                if (!ps.startsWith("/")) {
                                    ps = "/" + ps;
                                }/*from ww w  .ja v a  2 s .  c om*/
                                a.add(String.valueOf(ts), PREFIX + ps);
                            }
                            return a;
                        }, Functions.writeOnceBinaryOperator())));
    }
    return null;
}

From source file:at.ac.tuwien.infosys.util.ImageUtil.java

@PostConstruct
public void init() throws IOException {
    Path repo = Paths.get(workingRepo);
    Files.createDirectories(repo);
    this.imageTempDir = Files.createTempDirectory(Paths.get(repo.toString()), "image-");
    logger.info("Using temporary-folder: " + imageTempDir);
}

From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallPropertiesTaskTest.java

@Test
public void testRun() throws Exception {
    MicroServiceTask msTask = this.create();
    MicroServiceRest ms = msTask.getMs();

    Path propSrc = Paths/*from w  w w . j  av  a  2  s. c o  m*/
            .get(Thread.currentThread().getContextClassLoader().getResource("samples.ms.properties").toURI());
    byte[] propContent = Files.readAllBytes(propSrc);
    when(msService.getContentOfProperties(eq(ms.getName()))).thenReturn(propContent);

    Path msVersionFolder = Paths.get(this.nodeBase, ms.getName(), ms.getVersion());
    ;
    Files.createDirectories(msVersionFolder);

    task.run(msTask);

    Path appProp = Paths.get(msVersionFolder.toString(), "application.properties");
    assertTrue(Files.exists(appProp));
    assertArrayEquals(propContent, Files.readAllBytes(appProp));
}

From source file:io.ecarf.core.utils.UsageParser.java

public UsageParser(String folder) throws Exception {

    super();/*w  w w  .jav  a  2  s.  co m*/

    boolean remote = folder.startsWith(GoogleMetaData.CLOUD_STORAGE_PREFIX);

    if (remote) {

        String bucket = StringUtils.remove(folder, GoogleMetaData.CLOUD_STORAGE_PREFIX);
        this.setUp();
        List<StorageObject> objects = this.service.listCloudStorageObjects(bucket);

        for (StorageObject object : objects) {
            String name = object.getName();
            if (name.endsWith(Constants.DOT_LOG)) {
                String localFile = FilenameUtils.getLocalFilePath(name);

                service.downloadObjectFromCloudStorage(name, localFile, bucket);

                this.files.add(localFile);
            }
        }

    } else {
        // local file
        DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
            public boolean accept(Path file) throws IOException {

                String filename = file.toString();
                return filename.contains(USAGE_PREFIX);
            }
        };

        Path dir = Paths.get(folder);
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
            for (Path path : stream) {
                this.files.add(path.toString());
            }
        }
    }
}

From source file:misc.FileHandler.java

/**
 * Returns the group access bundle for the given folder.
 * /*  w  ww  .java  2 s.c o  m*/
 * @param prefix
 *            the path to the client's root directory. May not be
 *            <code>null</code>.
 * @param folder
 *            a folder path relative to prefix containing a group access
 *            bundle. May not be <code>null</code>.
 * @return the parsed access bundle, if the bundle exists and the bundle is
 *         syntactically correct. <code>null</code>, otherwise.
 */
public static GroupAccessBundle getGroupAccessBundle(Path prefix, Path folder) {
    if (prefix == null) {
        throw new NullPointerException("prefix may not be null!");
    }
    if (folder == null) {
        throw new NullPointerException("folder may not be null!");
    }

    Path location = Paths.get(prefix.toString(), folder.toString(), AccessBundle.ACCESS_BUNDLE_FILENAME);

    if (Files.exists(location)) {
        try {
            return GroupAccessBundle.parse(location);
        } catch (IOException | ParseException e) {
            Logger.logError(e);
        }
    }

    return null;
}

From source file:misc.FileHandler.java

/**
 * Returns the owner access bundle for the given folder.
 * /*  ww  w .  j a va  2s.  c  o  m*/
 * @param prefix
 *            the path to the client's root directory. May not be
 *            <code>null</code>.
 * @param folder
 *            a folder path relative to prefix containing an owner access
 *            bundle. May not be <code>null</code>.
 * @return the parsed access bundle, if the bundle exists and the bundle is
 *         syntactically correct. <code>null</code>, otherwise.
 */
public static OwnerAccessBundle getOwnerAccessBundle(Path prefix, Path folder) {
    if (prefix == null) {
        throw new NullPointerException("prefix may not be null!");
    }
    if (folder == null) {
        throw new NullPointerException("folder may not be null!");
    }

    Path location = Paths.get(prefix.toString(), folder.toString(), AccessBundle.ACCESS_BUNDLE_FILENAME);

    if (Files.exists(location)) {
        try {
            return OwnerAccessBundle.parse(location);
        } catch (IOException | ParseException e) {
            Logger.logError(e);
        }
    }

    return null;
}

From source file:eu.forgetit.middleware.cmis.FileshareRepositoryManager.java

@Override
public void fetchContentAndMetadata(String cmisId, Path destPath) {

    Path contentPath = Paths.get(destPath.toString(), "content");
    Path metadataPath = Paths.get(destPath.toString(), "metadata");

    try {//  ww  w .  jav  a  2  s .c  om

        Files.createDirectories(contentPath);
        Files.createDirectories(metadataPath);

        String contentType = getObjectType(cmisId);

        if (contentType.equals("cmis:document")) {

            Path contentFilePath = super.getObjectStream(cmisId, contentPath, null);

            logger.debug("Copied CMIS Object " + cmisId + " to file " + contentFilePath);

        }

    } catch (IOException e) {

        e.printStackTrace();
    }

}

From source file:com.nike.cerberus.operation.core.UploadCertFilesOperation.java

private String getFileContents(final Path path, final String filename) {
    Preconditions.checkNotNull(path);/*  ww w  . ja v a  2s. c  om*/
    Preconditions.checkNotNull(filename);

    File file = new File(path.toString(), filename);
    if (file.exists() && file.canRead()) {
        try {
            return new String(Files.readAllBytes(file.toPath()), Charset.forName("UTF-8"));
        } catch (IOException e) {
            throw new IllegalStateException("Failed to read the following file: " + file.getAbsolutePath());
        }
    } else {
        throw new IllegalArgumentException("The file is not readable: " + file.getAbsolutePath());
    }
}

From source file:at.ac.tuwien.infosys.util.ImageUtil.java

public synchronized Path createImage(Plan deviceComponentBundle, String idPrefix) throws IOException {

    if (idPrefix != null && !idPrefix.isEmpty())
        idPrefix += "_";
    else//from   www. j a  v  a 2s  . co  m
        idPrefix = "unknown_";

    this.imageId = idPrefix + UUID.randomUUID().toString();

    logger.info("Building image with id: " + imageId);

    this.zipUtil = new ZipUtil(imageId + ".zip", imageTempDir, workingRepo);

    List<String> componentNames = new ArrayList<String>();

    // create image structure and copy files (artifacts and scripts)
    for (Component component : deviceComponentBundle.getComponents()) {
        Path compParentPath = Files.createDirectories(imageTempDir.resolve(component.getName()));
        componentNames.add(component.getName());

        Path artifactParentPath = Files.createDirectories(compParentPath.resolve("artifacts"));

        Path scriptParentPath = Files.createDirectories(compParentPath.resolve("scripts"));

        for (Resource artifact : component.getBinaries()) {
            Path artifactFile = Files.createFile(artifactParentPath.resolve(artifact.getName()));
            saveFile(artifact.getUri(), artifactFile);
        }

        for (Resource script : component.getScripts()) {
            Path scriptFile = Files.createFile(scriptParentPath.resolve(script.getName()));
            saveFile(script.getUri(), scriptFile);
        }
    }

    // create runlist file and write component-names
    StringBuilder builder = new StringBuilder();
    // boolean firstItem = true;
    for (String componentName : componentNames) {
        // if (!firstItem)
        // builder.append("\n");
        // else
        // firstItem = false;
        // builder.append(componentName);
        builder.append(componentName + "\n");
    }
    Path runlistFile = Files.createFile(imageTempDir.resolve(RUNLIST_FILE));
    Files.write(runlistFile, builder.toString().getBytes());

    // create file and write image-id
    Path idFile = Files.createFile(imageTempDir.resolve(ID_FILE));
    Files.write(idFile, imageId.getBytes());

    // add generic image-run script
    Path globalRunFile = Files.createFile(imageTempDir.resolve(IMAGE_RUN_FILE_NAME));
    saveFile(Config.IMAGE_RUN_SCRIPT, globalRunFile);

    logger.info("Finished building and initiate archiving!");

    // create final image by compressing the contents into a zip
    Path zipFile = zipUtil.createZip();

    logger.info("Finished archiving image: " + zipFile.toString());

    return zipFile;
}