Example usage for java.net URI normalize

List of usage examples for java.net URI normalize

Introduction

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

Prototype

public URI normalize() 

Source Link

Document

Normalizes this URI's path.

Usage

From source file:savant.data.sources.BAMDataSource.java

public BAMDataSource(URI uri) throws IOException {
    this.uri = uri.normalize();

    File indexFile = IndexCache.getIndexFile(uri, "bai", "bam");
    SeekableStream stream = NetworkUtils.getSeekableStreamForURI(uri);
    samFileReader = new SAMFileReader(stream, indexFile, false);
    samFileReader.setValidationStringency(SAMFileReader.ValidationStringency.SILENT);
    samFileHeader = samFileReader.getFileHeader();
}

From source file:stargate.drivers.sourcefs.hdfs.HDFSChunkReader.java

public HDFSChunkReader(URI resourceUri, long offset, int size) throws IOException {
    Path path = new Path(resourceUri.normalize());
    FileSystem fs = path.getFileSystem(new Configuration());
    FSDataInputStream is = fs.open(path, BUFFER_SIZE);

    initialize(is, offset, size);/*from   w  w w  .j a v  a2s  .  c  om*/
}

From source file:org.wso2.carbon.ml.core.impl.BAMInputAdapter.java

/**
 * Checks whether the data source uri refers to a valid table in BAM
 * // ww  w  .  j a v  a  2  s .  c  om
 * @param uri   Data Source URI to be validated.
 * @return      Boolean indicating validity
 * @throws      MLInputAdapterException
 * @throws      ClientProtocolException
 * @throws      IOException
 */
private boolean isValidTable(URI uri) throws MLInputAdapterException, ClientProtocolException, IOException {
    httpClient = HttpClients.createDefault();
    uriResourceParameters = uri.normalize().getPath().replaceFirst("/analytics/tables", "").replaceAll("^/", "")
            .replaceAll("/$", "").split("/");
    // if BAM table name is not empty, return false.
    if (uriResourceParameters[0].isEmpty()) {
        return false;
    }
    // check whether the BAM table exists.
    try {
        URI tableCheckUri = new URI(uri.getScheme() + "://" + uri.getRawAuthority()
                + "/analytics/table_exists?tableName=" + uriResourceParameters[0]);
        HttpGet get = new HttpGet(tableCheckUri);
        CloseableHttpResponse response = httpClient.execute(get);
        BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        JSONObject outputJson = new JSONObject(br.readLine());
        return "success".equalsIgnoreCase(outputJson.get("status").toString());
    } catch (URISyntaxException e) {
        throw new MLInputAdapterException("Invalid Uri Syntax:" + e.getMessage(), e);
    }
}

From source file:org.apache.juddi.v3.client.mapping.wsdl.WSDLLocatorImpl.java

/**
 * Internal method to normalize the importUrl. The importLocation can be
 * relative to the parentLocation.//w  ww. java 2s  . co  m
 *
 * @param parentLocation
 * @param importLocation
 * @return a url
 */
protected URL constructImportUrl(String parentLocation, String importLocation) {
    URL importUrl = null;
    try {
        URI importLocationURI = new URI(importLocation);
        if (importLocationURI.getScheme() != null || parentLocation == null) {
            importUrl = importLocationURI.toURL();
        } else {
            String parentDir = parentLocation.substring(0, parentLocation.lastIndexOf("/"));
            URI uri = new URI(parentDir + "/" + importLocation);
            importUrl = uri.normalize().toURL();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    if (importUrl != null) {
        log.debug("importUrl: " + importUrl.toExternalForm());
    } else {
        log.error("importUrl is null!");
    }
    return importUrl;
}

From source file:hsyndicate.fs.SyndicateFSPath.java

private URI createPathUri(String scheme, String authority, String path) {
    try {//from ww  w .  jav  a  2s.c  o m
        URI uri = new URI(scheme, authority, normalizePath(path), null, null);
        return uri.normalize();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:eu.planets_project.tb.gui.backing.FileBrowser.java

/**
 * @param location the location to set//  w w  w .  j av  a  2  s  .  c om
 */
public void setLocation(URI location) {
    log.debug("Setting location: " + location);
    if (location != null)
        this.location = location.normalize();
    DigitalObjectReference[] dobs = dr.list(this.location);
    int fileCount = 0;
    for (DigitalObjectReference dob : dobs) {
        if (!dob.isDirectory())
            fileCount++;
    }
    //this.currentItems = new FileTreeNode[fileCount];
    // Put directories first.
    this.currentItems = new FileTreeNode[dobs.length];
    int i = 0;
    for (DigitalObjectReference dob : dobs) {
        if (dob.isDirectory()) {
            this.currentItems[i] = new FileTreeNode(dob);
            i++;
        }
    }
    for (DigitalObjectReference dob : dobs) {
        if (!dob.isDirectory()) {
            this.currentItems[i] = new FileTreeNode(dob);
            i++;
        }
    }
    /*
    if( this.getParentExists() ) {
      this.currentItems = new DigitalObject[listItems.length+1];
      try {
    this.currentItems[0] = new DigitalObject(new URI(this.location+"/.."));
    this.currentItems[0].setDirectory(true);
    this.currentItems[0].setSelectable(false);
      } catch( java.net.URISyntaxException e ) {
      log.error("Failed to create parent URI: " + e );
      this.currentItems = listItems;
      }
      System.arraycopy(listItems, 0, this.currentItems, 1, listItems.length);
    } else {
      this.currentItems = listItems;
    }*/
}

From source file:org.esigate.impl.UrlRewriter.java

/**
 * Fixes an url according to the chosen mode.
 * //  w  w  w. j a  v  a2s  .  c o  m
 * @param url
 *            the url to fix (can be anything found in an html page, relative, absolute, empty...)
 * @param requestUrl
 *            The incoming request URL (could be absolute or relative to visible base url).
 * @param baseUrl
 *            The base URL selected for this request.
 * @param visibleBaseUrl
 *            The base URL viewed by the browser.
 * @param absolute
 *            Should the rewritten urls contain the scheme host and port
 * 
 * @return the fixed url.
 */
public String rewriteUrl(String url, String requestUrl, String baseUrl, String visibleBaseUrl,
        boolean absolute) {
    // Base url should end with /
    if (!baseUrl.endsWith("/")) {
        baseUrl = baseUrl + "/";
    }
    URI baseUri = UriUtils.createURI(baseUrl);

    // If no visible url base is defined, use base url as visible base url
    if (!visibleBaseUrl.endsWith("/")) {
        visibleBaseUrl = visibleBaseUrl + "/";
    }
    URI visibleBaseUri = UriUtils.createURI(visibleBaseUrl);

    // Build the absolute Uri of the request sent to the backend
    URI requestUri;
    if (requestUrl.startsWith(visibleBaseUrl)) {
        requestUri = UriUtils.createURI(requestUrl);
    } else {
        requestUri = UriUtils.concatPath(baseUri, requestUrl);
    }

    // Interpret the url relatively to the request url (may be relative)
    URI uri = UriUtils.resolve(url, requestUri);
    // Normalize the path (remove . or .. if possible)
    uri = uri.normalize();

    // Try to relativize url to base url
    URI relativeUri = baseUri.relativize(uri);
    // If the url is unchanged do nothing
    if (relativeUri.equals(uri)) {
        LOG.debug("url kept unchanged: [{}]", url);
        return url;
    }
    // Else rewrite replacing baseUrl by visibleBaseUrl
    URI result = visibleBaseUri.resolve(relativeUri);
    // If mode relative, remove all the scheme://host:port to keep only a url relative to server root (starts with
    // "/")
    if (!absolute) {
        result = UriUtils.removeServer(result);
    }
    LOG.debug("url fixed: [{}] -> [{}]", url, result);
    return result.toString();
}

From source file:com.buaa.cfs.fs.Path.java

/**
 * Construct a path from a URI
 */
public Path(URI aUri) {
    uri = aUri.normalize();
}

From source file:com.digitalpebble.stormcrawler.filtering.basic.BasicURLNormalizer.java

@Override
public String filter(URL sourceUrl, Metadata sourceMetadata, String urlToFilter) {

    urlToFilter = urlToFilter.trim();/* w  w  w .ja  v  a  2 s  .  c  o m*/

    if (removeAnchorPart) {
        try {
            URL theURL = new URL(urlToFilter);
            String anchor = theURL.getRef();
            if (anchor != null)
                urlToFilter = urlToFilter.replace("#" + anchor, "");
        } catch (MalformedURLException e) {
            return null;
        }
    }

    if (unmangleQueryString) {
        urlToFilter = unmangleQueryString(urlToFilter);
    }

    if (!queryElementsToRemove.isEmpty()) {
        urlToFilter = filterQueryElements(urlToFilter);
    }

    try {
        URL theURL = new URL(urlToFilter);
        String file = theURL.getFile();
        String protocol = theURL.getProtocol();
        String host = theURL.getHost();
        boolean hasChanged = false;

        // lowercased protocol
        if (!urlToFilter.startsWith(protocol)) {
            hasChanged = true;
        }

        if (host != null) {
            String newHost = host.toLowerCase(Locale.ROOT);
            if (!host.equals(newHost)) {
                host = newHost;
                hasChanged = true;
            }
        }

        int port = theURL.getPort();
        // properly encode characters in path/file using percent-encoding
        String file2 = unescapePath(file);
        file2 = escapePath(file2);
        if (!file.equals(file2)) {
            hasChanged = true;
        }
        if (hasChanged) {
            urlToFilter = new URL(protocol, host, port, file2).toString();
        }
    } catch (MalformedURLException e) {
        return null;
    }

    if (checkValidURI) {
        try {
            URI uri = URI.create(urlToFilter);
            urlToFilter = uri.normalize().toString();
        } catch (java.lang.IllegalArgumentException e) {
            LOG.info("Invalid URI {}", urlToFilter);
            return null;
        }
    }

    return urlToFilter;
}

From source file:savant.file.SavantROFile.java

/**
 * Construct a Savant file from a URI/*from   ww  w. ja  va 2 s .  c  o m*/
 *
 * @param uri http, ftp (or file) URI
 * @throws IOException
 * @throws SavantFileNotFormattedException if file is not formatted in Savant format (no magic number)
 * @throws SavantUnsupportedVersionException if file is formatted in a currently unsupported version
 */
public SavantROFile(URI uri) throws IOException, SavantFileNotFormattedException {
    this.uri = uri.normalize();
    seekStream = NetworkUtils.getSeekableStreamForURI(uri);
    init();
}