Example usage for java.net URI getRawSchemeSpecificPart

List of usage examples for java.net URI getRawSchemeSpecificPart

Introduction

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

Prototype

public String getRawSchemeSpecificPart() 

Source Link

Document

Returns the raw scheme-specific part of this URI.

Usage

From source file:com.mcxiaoke.next.http.util.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Charsets.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}

From source file:com.smartitengineering.util.simple.reflection.DefaultClassScannerImpl.java

private void scanForVisit(URI u, String filePackageName, ClassVisitor classVisitor) {
    String scheme = u.getScheme();
    if (scheme.equals("file")) {
        File f = new File(u.getPath());
        if (f.isDirectory()) {
            scanDir(f, false, classVisitor);
        } else {/* w  w w  .j  a va 2 s.  c o  m*/
        }
    } else if (scheme.equals("jar") || scheme.equals("zip")) {
        URI jarUri = URI.create(u.getRawSchemeSpecificPart());
        String jarFile = jarUri.getPath();
        jarFile = jarFile.substring(0, jarFile.indexOf('!'));
        scanJar(new File(jarFile), filePackageName, classVisitor);
    } else {
    }
}

From source file:dk.netarkivet.common.distribute.arcrepository.ARCLookup.java

/** Look up a given URI and return the contents as an InputStream.
 * The uri is first checked using url-decoding (e.g. "," in the argument
 * is converted to "%2C"). If this returns no match, the method then
 * searches for a non-url-decoded match. If neither returns a match
 * the method returns null./*from w ww .j  a  v  a  2 s .c om*/
 * 
 * If the tryToLookupUriAsFtp field is set to true, we will try exchanging
 * the schema with ftp, whenever we can't lookup the uri with the original
 * schema.
 *
 * @param uri The URI to find in the archive.  If the URI does not
 * match any entries in the archive, null is returned.
 * @return An InputStream Containing all the data in the entry, or
 * null if the entry was not found
 * @throws IOFailure If the ARC file was found in the Lucene index but not
 * in the bit archive, or if some other failure happened while finding
 * the file.
 */
public ResultStream lookup(URI uri) {
    ArgumentNotValid.checkNotNull(uri, "uri");
    boolean containsHeader = true;
    // the URI.getSchemeSpecificPart() carries out the url-decoding
    ARCKey key = luceneLookup(uri.getScheme() + ":" + uri.getSchemeSpecificPart());
    if (key == null) {
        // the URI.getRawSchemeSpecificPart() returns the uri in non-decoded form
        key = luceneLookup(uri.getScheme() + ":" + uri.getRawSchemeSpecificPart());
    }

    if (key == null && tryToLookupUriAsFtp) {
        log.debug(
                "Url not found with the schema '" + uri.getScheme() + ". Now trying with 'ftp' as the schema");
        final String ftpSchema = "ftp";
        key = luceneLookup(ftpSchema + ":" + uri.getSchemeSpecificPart());
        if (key == null) {
            key = luceneLookup(ftpSchema + ":" + uri.getRawSchemeSpecificPart());
            if (key != null) {
                // Remember, that the found ftp-records don't have any HTTP
                // Header
                containsHeader = false;
            }
        } else {
            // Remember, that the found ftp-record don't have any HTTP
            // Header
            containsHeader = false;
        }
    }

    if (key == null) {
        return null; // key not found
    } else {
        final BitarchiveRecord bitarchiveRecord = arcRepositoryClient.get(key.getFile().getName(),
                key.getOffset());
        if (bitarchiveRecord == null) {
            String message = "ARC file '" + key.getFile().getName()
                    + "' mentioned in index file was not found by" + " arc repository. This may mean we have a"
                    + " timeout, or that the index is wrong; or" + " it may mean we have lost a record in"
                    + " the bitarchives.";
            log.debug(message);
            throw new IOFailure(message);
        }
        return new ResultStream(bitarchiveRecord.getData(), containsHeader);
    }
}

From source file:de.fiz.akubra.hdfs.HDFSBlobStoreConnection.java

/**
 * fetch a {@link HDFSBlob} from the {@link HDFSBlobStore}
 * //  w  w  w .j  a  v a  2 s .  com
 * @param uri
 *            the {@link URI} of the {@link HDFSBlob}
 * @param hints
 *            not used
 * @throws UnsupportedIdException
 *             if the supplied {@link URI} was not valid
 */
public Blob getBlob(final URI uri, final Map<String, String> hints) throws UnsupportedIdException, IOException {
    if (isClosed()) {
        throw new IllegalStateException("Connection to hdfs is closed");
    }
    if (uri == null) {
        URI tmp = URI.create(store.getId() + UUID.randomUUID().toString());
        log.debug("creating new Blob uri " + tmp.toASCIIString());
        // return getBlob(new ByteArrayInputStream(new byte[0]),0, null);
        return new HDFSBlob(tmp, this);
    }
    log.debug("fetching blob " + uri);
    if (uri.getRawSchemeSpecificPart().startsWith("info:")) {
        log.debug("special object " + uri);
    }
    if (!uri.toASCIIString().startsWith("hdfs:")) {
        throw new UnsupportedIdException(uri, "HDFS URIs have to start with 'hdfs:'");
    }
    HDFSBlob blob = new HDFSBlob(uri, this);
    return blob;
}

From source file:org.cryptomator.webdav.WebDavServer.java

/**
 * @param workDir Path of encrypted folder.
 * @param cryptor A fully initialized cryptor instance ready to en- or decrypt streams.
 * @param failingMacCollection A (observable, thread-safe) collection, to which the names of resources are written, whose MAC
 *            authentication fails./*from  w  w  w.  j a v a2 s .  c o  m*/
 * @param name The name of the folder. Must be non-empty and only contain any of
 *            _ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
 * @return servlet
 */
public ServletLifeCycleAdapter createServlet(final Path workDir, final Cryptor cryptor,
        final Collection<String> failingMacCollection, final String name) {
    try {
        if (StringUtils.isEmpty(name)) {
            throw new IllegalArgumentException("name empty");
        }
        if (!StringUtils.containsOnly(name,
                "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")) {
            throw new IllegalArgumentException("name contains illegal characters: " + name);
        }
        final URI uri = new URI(null, null, localConnector.getHost(), localConnector.getLocalPort(),
                "/" + UUID.randomUUID().toString() + "/" + name, null, null);

        final ServletContextHandler servletContext = new ServletContextHandler(servletCollection,
                uri.getRawPath(), ServletContextHandler.SESSIONS);
        final ServletHolder servlet = getWebDavServletHolder(workDir.toString(), cryptor, failingMacCollection);
        servletContext.addServlet(servlet, "/*");

        servletCollection.mapContexts();

        LOG.debug("{} available on http:{}", workDir, uri.getRawSchemeSpecificPart());
        return new ServletLifeCycleAdapter(servletContext, uri);
    } catch (URISyntaxException e) {
        throw new IllegalStateException("Invalid hard-coded URI components.", e);
    }
}

From source file:org.apache.manifoldcf.agents.output.filesystem.FileOutputConnector.java

/**
 * @param documentURI/* w  w  w .  j  a v  a  2s  .  c om*/
 * @return
 * @throws URISyntaxException
 * @throws NullPointerException
 */
final private String documentURItoFilePath(String documentURI) throws URISyntaxException, NullPointerException {
    StringBuffer path = new StringBuffer();
    URI uri = null;

    uri = new URI(documentURI);

    if (uri.getScheme() != null) {
        path.append(uri.getScheme());
        path.append("/");
    }

    if (uri.getHost() != null) {
        path.append(uri.getHost());
        if (uri.getPort() != -1) {
            path.append(":");
            path.append(uri.getPort());
        }
        if (uri.getRawPath() != null) {
            if (uri.getRawPath().length() == 0) {
                path.append("/");
            } else if (uri.getRawPath().equals("/")) {
                path.append(uri.getRawPath());
            } else {
                for (String name : uri.getRawPath().split("/")) {
                    if (name.length() > 0) {
                        path.append("/");
                        path.append(convertString(name));
                    }
                }
            }
        }
        if (uri.getRawQuery() != null) {
            path.append("?");
            path.append(convertString(uri.getRawQuery()));
        }
    } else {
        if (uri.getRawSchemeSpecificPart() != null) {
            for (String name : uri.getRawSchemeSpecificPart().split("/")) {
                if (name.length() > 0) {
                    path.append("/");
                    path.append(convertString(name));
                }
            }
        }
    }

    if (path.toString().endsWith("/")) {
        path.append(".content");
    }
    return path.toString();
}

From source file:org.apache.manifoldcf.agents.output.hdfs.HDFSOutputConnector.java

/**
 * @param documentURI/*w w  w.j  a  v a  2s  .c  om*/
 * @return
 * @throws URISyntaxException
 */
final private String documentURItoFilePath(String documentURI) throws URISyntaxException {
    StringBuffer path = new StringBuffer();
    URI uri = null;

    uri = new URI(documentURI);

    if (uri.getScheme() != null) {
        path.append(uri.getScheme());
        path.append("/");
    }

    if (uri.getHost() != null) {
        path.append(uri.getHost());
        if (uri.getPort() != -1) {
            path.append(":");
            path.append(Integer.toString(uri.getPort()));
        }
        if (uri.getRawPath() != null) {
            if (uri.getRawPath().length() == 0) {
                path.append("/");
            } else if (uri.getRawPath().equals("/")) {
                path.append(uri.getRawPath());
            } else {
                for (String name : uri.getRawPath().split("/")) {
                    if (name != null && name.length() > 0) {
                        path.append("/");
                        path.append(name);
                    }
                }
            }
        }
        if (uri.getRawQuery() != null) {
            path.append("?");
            path.append(uri.getRawQuery());
        }
    } else {
        if (uri.getRawSchemeSpecificPart() != null) {
            for (String name : uri.getRawSchemeSpecificPart().split("/")) {
                if (name != null && name.length() > 0) {
                    path.append("/");
                    path.append(name);
                }
            }
        }
    }

    if (path.toString().endsWith("/")) {
        path.append(".content");
    }
    return path.toString();
}