Example usage for java.net URI getPath

List of usage examples for java.net URI getPath

Introduction

In this page you can find the example usage for java.net URI getPath.

Prototype

public String getPath() 

Source Link

Document

Returns the decoded path component of this URI.

Usage

From source file:io.stallion.contentPublishing.UploadRequestProcessor.java

protected File downloadExternalToLocalFile(U uploaded) {

    URI uri = URI.create(urlToFetch);

    String fullFileName = FilenameUtils.getName(uri.getPath());
    String extension = FilenameUtils.getExtension(fullFileName);
    String fileName = truncate(fullFileName, 85);
    String relativePath = GeneralUtils.slugify(truncate(FilenameUtils.getBaseName(fullFileName), 75)) + "-"
            + DateUtils.mils() + "." + extension;
    relativePath = "stallion-file-" + uploaded.getId() + "/" + GeneralUtils.secureRandomToken(8) + "/"
            + relativePath;//from  ww w  .ja v  a 2 s.com

    String destPath = uploadsFolder + relativePath;
    try {
        FileUtils.forceMkdir(new File(destPath).getParentFile());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    uploaded.setCloudKey(relativePath).setExtension(extension).setName(fileName)
            .setOwnerId(Context.getUser().getId()).setUploadedAt(DateUtils.utcNow())
            .setType(fileController.getTypeForExtension(extension));

    // Make raw URL
    String url = makeRawUrlForFile(uploaded, "org");
    uploaded.setRawUrl(url);

    fileController.save(uploaded);

    File outFile = new File(destPath);

    try {
        IOUtils.copy(Unirest.get(urlToFetch).asBinary().getRawBody(),
                org.apache.commons.io.FileUtils.openOutputStream(outFile));
    } catch (UnirestException e) {
        throw new ClientException("Error downloading file from " + url + ": " + e.getMessage(), 400, e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return outFile;

}

From source file:org.datacleaner.user.MonitorConnection.java

/**
 * Determines if a {@link URI} matches the configured DC Monitor settings.
 * /*from ww  w. jav  a2s .  co  m*/
 * @param uri
 * @return
 */
public boolean matchesURI(URI uri) {
    if (uri == null) {
        return false;
    }
    final String host = uri.getHost();
    if (host.equals(_hostname)) {
        final int port = uri.getPort();
        if (port == _port || port == -1) {
            final String path = removeBeginningSlash(uri.getPath());
            if (StringUtils.isNullOrEmpty(_contextPath) || path.startsWith(_contextPath)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.esri.geoportal.commons.http.BotsHttpClient.java

private URI updateURI(URI uri, PHP php) throws URISyntaxException {
    return new URI(php.protocol != null ? php.protocol : uri.getScheme(), uri.getUserInfo(),
            php.host != null ? php.host : uri.getHost(),
            php.host != null ? php.port != null ? php.port : -1 : uri.getPort(), uri.getPath(), uri.getQuery(),
            uri.getFragment());//from   w  ww  .  j  av  a 2  s.c o  m
}

From source file:hsyndicate.fs.SyndicateFSPath.java

public SyndicateFSPath(SyndicateFSPath parent, SyndicateFSPath child) {
    if (parent == null)
        throw new IllegalArgumentException("Can not resolve a path from a null parent");
    if (child == null)
        throw new IllegalArgumentException("Can not resolve a path from a null child");

    URI parentUri = parent.uri;
    if (parentUri == null)
        throw new IllegalArgumentException("Can not resolve a path from a null parent URI");

    String parentPath = parentUri.getPath();

    if (!(parentPath.equals("/") || parentPath.equals(""))) {
        // parent path is not empty -- need to parse
        try {//from  www.j a  v  a 2 s  .  c om
            parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(), parentUri.getPath() + "/",
                    null, parentUri.getFragment());
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }

    URI resolved = parentUri.resolve(child.uri);

    // assign resolved uri to member field
    this.uri = createPathUri(resolved.getScheme(), resolved.getAuthority(), normalizePath(resolved.getPath()));
    //LOG.info("path - " + uri.toString());
}

From source file:com.abiquo.abiserver.pojo.service.RemoteService.java

/**
 * Sets the uri./*from  w  w  w. j  av  a 2  s. c  om*/
 * 
 * @param uri the new uri
 */
public void setUri(final String uri) {
    this.uri = uri;
    URI u = URI.create(uri);

    this.protocol = fixProtocol(u.getScheme());
    this.domainName = u.getHost();
    this.port = u.getPort();
    if (port == -1) {
        port = 80;
    }
    this.serviceMapping = u.getPath();
    if (serviceMapping.startsWith("/")) {
        serviceMapping = serviceMapping.replaceFirst("/", "");
    }
}

From source file:com.googlecode.psiprobe.Tomcat80ContainerAdaptor.java

public File getConfigFile(Context ctx) {
    URL configUrl = ctx.getConfigFile();
    if (configUrl != null) {
        try {/*w w  w . j a  v a 2  s. co m*/
            URI configUri = configUrl.toURI();
            if ("file".equals(configUri.getScheme())) {
                return new File(configUri.getPath());
            }
        } catch (Exception ex) {
            logger.error("Could not convert URL to URI: " + configUrl, ex);
        }
    }
    return null;
}

From source file:edu.arizona.cs.hadoop.fs.irods.output.HirodsFileOutputCommitter.java

/**
 * Find the final name of a given output file, given the job output
 * directory and the work directory.//from   www  . ja v a 2s  .  c o  m
 *
 * @param jobOutputDir the job's output directory
 * @param taskOutput the specific task output file
 * @param taskOutputPath the job's work directory
 * @return the final path for the specific output file
 * @throws IOException
 */
private Path getFinalPath(Path jobOutputDir, Path taskOutput, Path taskOutputPath) throws IOException {
    URI taskOutputUri = taskOutput.toUri();
    URI relativePath = taskOutputPath.toUri().relativize(taskOutputUri);
    if (taskOutputUri == relativePath) {
        throw new IOException(
                "Can not get the relative path: base = " + taskOutputPath + " child = " + taskOutput);
    }
    if (relativePath.getPath().length() > 0) {
        return new Path(jobOutputDir, relativePath.getPath());
    } else {
        return jobOutputDir;
    }
}

From source file:org.apache.storm.scheduler.utils.ArtifactoryConfigLoader.java

private Map loadFromURI(URI uri) throws IOException {
    String host = uri.getHost();/*from w ww.jav a  2s . co m*/
    Integer port = uri.getPort();
    String location = uri.getPath();
    if (location.toLowerCase().startsWith(baseDirectory.toLowerCase())) {
        location = location.substring(baseDirectory.length());
    }

    if (!cacheInitialized) {
        makeArtifactoryCache(location);
    }

    // Get the most recent artifact as a String, and then parse the yaml
    String yamlConfig = loadMostRecentArtifact(location, host, port);

    // If we failed to get anything from Artifactory try to get it from our local cache
    if (yamlConfig == null) {
        Map ret = getLatestFromCache();
        updateLastReturned(ret);
        return ret;
    }

    // Now parse it and return the map.
    Yaml yaml = new Yaml(new SafeConstructor());
    Map ret = null;
    try {
        ret = (Map) yaml.load(yamlConfig);
    } catch (Exception e) {
        LOG.error("Could not parse yaml.");
        return null;
    }

    if (ret != null) {
        LOG.debug("returning a new map from Artifactory");
        updateLastReturned(ret);
        return ret;
    }

    return null;
}

From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java

public UriBuilder newUri(URI root) {
    String rootPath = root.getPath();
    if (!rootPath.endsWith("/")) {
        try {//from www .  java  2s . c  om
            return new UriBuilder(new URI(root.getScheme(), root.getHost() + ":" + root.getPort(),
                    rootPath + "/", root.getQuery(), root.getFragment()));
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
    return new UriBuilder(root);
}