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:edu.usc.goffish.gofs.namenode.DataNode.java

@Override
public IPartition loadLocalPartition(String graphId, int partitionId) throws IOException {
    URI partitionURI = _nameNode.getPartitionDirectory().getPartitionMapping(graphId, partitionId);
    URI relativization = _localhostURI.relativize(partitionURI);

    if (relativization == partitionURI) {
        // given partition is not in this data node
        throw new IllegalArgumentException();
    }/*from w ww.ja v a2 s.  c  o  m*/

    Path slicePath = _dataNodeSliceDirPath.resolve(relativization.getPath());

    UUID partitionUUID;
    try {
        partitionUUID = UUID.fromString(relativization.getFragment());
    } catch (NullPointerException | IllegalArgumentException e) {
        // bad fragment returned by partition directory
        throw new IllegalStateException(e);
    }

    return SliceManager.create(partitionUUID, _sliceSerializer, new FileStorageManager(slicePath))
            .readPartition();
}

From source file:eu.planets_project.tb.gui.backing.data.DigitalObjectTreeNode.java

/** */
private void setUri(URI uri) {
    this.uri = uri;
    if (this.uri != null) {
        this.leafname = uri.getPath();
        if (this.leafname != null) {
            String[] parts = this.leafname.split("/");
            if (parts != null && parts.length > 0)
                this.leafname = parts[parts.length - 1];
        }//www  . ja  va2s  . co  m
    } else {
        this.leafname = "/";
    }
}

From source file:io.seldon.external.ExternalPredictionServer.java

public JsonNode predict(String client, JsonNode jsonNode, OptionsHolder options) {
    long timeNow = System.currentTimeMillis();
    URI uri = URI.create(options.getStringOption(URL_PROPERTY_NAME));
    try {/*from www.  j  a  v  a  2  s .  c o  m*/
        URIBuilder builder = new URIBuilder().setScheme("http").setHost(uri.getHost()).setPort(uri.getPort())
                .setPath(uri.getPath()).setParameter("client", client)
                .setParameter("json", jsonNode.toString());

        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new APIException(APIException.GENERIC_ERROR);
    }
    HttpContext context = HttpClientContext.create();
    HttpGet httpGet = new HttpGet(uri);
    try {
        if (logger.isDebugEnabled())
            logger.debug("Requesting " + httpGet.getURI().toString());
        CloseableHttpResponse resp = httpClient.execute(httpGet, context);
        try {
            if (resp.getStatusLine().getStatusCode() == 200) {
                ObjectMapper mapper = new ObjectMapper();
                JsonFactory factory = mapper.getFactory();
                JsonParser parser = factory.createParser(resp.getEntity().getContent());
                JsonNode actualObj = mapper.readTree(parser);

                return actualObj;
            } else {
                logger.error(
                        "Couldn't retrieve prediction from external prediction server -- bad http return code: "
                                + resp.getStatusLine().getStatusCode());
                throw new APIException(APIException.GENERIC_ERROR);
            }
        } finally {
            if (resp != null)
                resp.close();
            if (logger.isDebugEnabled())
                logger.debug(
                        "External prediction server took " + (System.currentTimeMillis() - timeNow) + "ms");
        }
    } catch (IOException e) {
        logger.error("Couldn't retrieve prediction from external prediction server - ", e);
        throw new APIException(APIException.GENERIC_ERROR);
    } catch (Exception e) {
        logger.error("Couldn't retrieve prediction from external prediction server - ", e);
        throw new APIException(APIException.GENERIC_ERROR);
    } finally {

    }

}

From source file:com.anrisoftware.globalpom.checkfilehash.CheckFileHash.java

private HashName hashName(URI hashResource) {
    if (StringUtils.equals(hashResource.getScheme(), "md5")) {
        return HashName.forExtension("md5");
    } else if (StringUtils.equals(hashResource.getScheme(), "sha1")) {
        return HashName.forExtension("sha1");
    } else {/*  ww w.j  a  va  2s  .c om*/
        String ex = getExtension(hashResource.getPath());
        return HashName.forExtension(ex);
    }
}

From source file:org.droidparts.http.CookieJar.java

private Collection<Cookie> getCookies(URI uri) {
    HashMap<String, Cookie> map = new HashMap<String, Cookie>();
    for (Cookie cookie : getCookies()) {
        boolean suitable = uri.getHost().equals(cookie.getDomain())
                && uri.getPath().startsWith(cookie.getPath());
        if (suitable) {
            boolean put = true;
            if (map.containsKey(cookie.getName())) {
                Cookie otherCookie = map.get(cookie.getName());
                boolean betterMatchingPath = cookie.getPath().length() > otherCookie.getPath().length();
                put = betterMatchingPath;
            }/*  w ww  .java 2 s. c  o m*/
            if (put) {
                map.put(cookie.getName(), cookie);
            }
        }
    }
    return map.values();
}

From source file:com.inmobi.conduit.distcp.DistcpBaseService.java

/**
 * Method to qualify the checkpoint path based on the readurl configured
 * for the source cluster. The readurl of the cluster can change and the
 * checkpoint paths should be re-qualified to the new source cluster read
 * path./*  ww  w.  j  a  v  a2s .  c  om*/
 *
 * @param lastCheckPointPath path which can be null read from checkpoint
 *                           file.
 * @param srcCluster the cluster for which checkpoint file which should be
 *                   re-qualified.
 * @return path which is re-qualified.
 */
protected Path fullyQualifyCheckPointWithReadURL(Path lastCheckPointPath, Cluster srcCluster) {
    //if checkpoint value was empty or null just fall thro' let the service
    // determine the new path.
    if (lastCheckPointPath == null) {
        return null;
    }
    String readUrl = srcCluster.getReadUrl();
    URI checkpointURI = lastCheckPointPath.toUri();
    String unQualifiedPathStr = checkpointURI.getPath();
    Path newCheckPointPath = new Path(readUrl, unQualifiedPathStr);
    return newCheckPointPath;
}

From source file:fr.hoteia.qalingo.web.mvc.controller.catalog.AssetController.java

@RequestMapping(value = "/asset-form.html*", method = RequestMethod.POST)
public ModelAndView assetEdit(final HttpServletRequest request, final HttpServletResponse response,
        @Valid AssetForm assetForm, BindingResult result, ModelMap modelMap) throws Exception {

    if (result.hasErrors()) {
        return display(request, response, modelMap);
    }/*w ww  .j  ava  2 s  .  c o  m*/

    final String currentAssetId = assetForm.getId();
    final Asset asset = productMarketingService.getProductMarketingAssetById(currentAssetId);
    final String currentAssetCode = asset.getCode();

    MultipartFile multipartFile = assetForm.getFile();
    if (multipartFile != null) {
        long size = multipartFile.getSize();
        asset.setFileSize(size);
    }

    try {
        if (multipartFile.getSize() > 0) {
            String pathProductMarketingImage = multipartFile.getOriginalFilename();
            String assetFileRootPath = engineSettingService.getAssetFileRootPath().getDefaultValue();
            assetFileRootPath.replaceAll("\\\\", "/");
            if (assetFileRootPath.endsWith("/")) {
                assetFileRootPath = assetFileRootPath.substring(0, assetFileRootPath.length() - 1);
            }
            String assetProductMarketingFilePath = engineSettingService.getAssetProductMarketingFilePath()
                    .getDefaultValue();
            assetProductMarketingFilePath.replaceAll("\\\\", "/");
            if (assetProductMarketingFilePath.endsWith("/")) {
                assetProductMarketingFilePath = assetProductMarketingFilePath.substring(0,
                        assetProductMarketingFilePath.length() - 1);
            }
            if (!assetProductMarketingFilePath.startsWith("/")) {
                assetProductMarketingFilePath = "/" + assetProductMarketingFilePath;
            }

            String absoluteFilePath = assetFileRootPath + assetProductMarketingFilePath + "/"
                    + asset.getType().getPropertyKey().toLowerCase() + "/" + pathProductMarketingImage;

            InputStream inputStream = multipartFile.getInputStream();
            URI url = new URI(absoluteFilePath);
            File fileAsset;
            try {
                fileAsset = new File(url);
            } catch (IllegalArgumentException e) {
                fileAsset = new File(url.getPath());
            }
            OutputStream outputStream = new FileOutputStream(fileAsset);
            int readBytes = 0;
            byte[] buffer = new byte[8192];
            while ((readBytes = inputStream.read(buffer, 0, 8192)) != -1) {
                outputStream.write(buffer, 0, readBytes);
            }
            outputStream.close();
            inputStream.close();
            asset.setPath(pathProductMarketingImage);
        }

        // UPDATE ASSET
        webBackofficeService.updateProductMarketingAsset(asset, assetForm);

    } catch (Exception e) {
        LOG.error("Can't save/update asset file!", e);
    }

    final String urlRedirect = backofficeUrlService.buildAssetDetailsUrl(currentAssetCode);
    return new ModelAndView(new RedirectView(urlRedirect));
}

From source file:org.chtijbug.drools.platform.rules.config.RuntimeSiteTopology.java

public WebClient webClient(String envName, String resourcePath) {
    try {//from  w  ww . j  a  v  a2 s. c o m
        URI uri = environments.get(envName).getUrl().toURI();
        URI baseUri = uri.resolve("/");
        JacksonJaxbJsonProvider jsonProvider = new JacksonJaxbJsonProvider();
        WebClient client = WebClient.create(baseUri.toString(), asList(jsonProvider))
                .path(uri.getPath().concat(resourcePath));
        //_____ Adding no timeout feature for long running process
        ClientConfiguration config = WebClient.getConfig(client);
        HTTPConduit http = (HTTPConduit) config.getConduit();
        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
        /* connection timeout for requesting the rule package binaries */
        httpClientPolicy.setConnectionTimeout(0L);
        /* Reception timeout */
        httpClientPolicy.setReceiveTimeout(0L);
        http.setClient(httpClientPolicy);
        return client;
    } catch (URISyntaxException e) {
        throw propagate(e);
    }
}

From source file:org.bedework.synch.cnctrs.orgSyncV2.OrgSyncV2ConnectorInstance.java

@Override
public URI getUri() throws SynchException {
    try {/*w  ww . j  av a  2s .  c o  m*/
        //Get yesterdays date
        final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS);
        final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE);

        final URI infoUri = new URI(info.getUri());
        return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost())
                .setPort(infoUri.getPort()).setPath(infoUri.getPath())
                .setParameter("key", cnctr.getSyncher().decrypt(info.getPassword()))
                .setParameter("start_date", yesterdayStr).build();
    } catch (final SynchException se) {
        throw se;
    } catch (final Throwable t) {
        throw new SynchException(t);
    }
}