當前位置: 首頁>>代碼示例>>Java>>正文


Java URI.isOpaque方法代碼示例

本文整理匯總了Java中java.net.URI.isOpaque方法的典型用法代碼示例。如果您正苦於以下問題:Java URI.isOpaque方法的具體用法?Java URI.isOpaque怎麽用?Java URI.isOpaque使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URI的用法示例。


在下文中一共展示了URI.isOpaque方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateURL

import java.net.URI; //導入方法依賴的package包/類
private void validateURL(final URL url, final File file) {
    try {
        final URI uri = url.toURI();
        if (!uri.isAbsolute()) {
            throw new IllegalArgumentException("URI is not absolute: " + uri.toString() + " File: " + file.getAbsolutePath());   //NOI18N
        }
        if (uri.isOpaque()) {
            throw new IllegalArgumentException("URI is not hierarchical: " + uri.toString() + " File: " + file.getAbsolutePath());   //NOI18N
        }
        if (!"file".equals(uri.getScheme())) {
            throw new IllegalArgumentException("URI scheme is not \"file\": " + uri.toString() + " File: " + file.getAbsolutePath());   //NOI18N
        }
    } catch (URISyntaxException use) {
        throw new IllegalArgumentException(use);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:J2SEModularProjectProperties.java

示例2: matchNormalized

import java.net.URI; //導入方法依賴的package包/類
private boolean matchNormalized(URI uri) {
    if(uriPattern.isOpaque()) {
        // This url only has scheme, scheme-specific part and fragment
        return uri.isOpaque() &&
                match(uriPattern.getScheme(), uri.getScheme()) &&
                match(uriPattern.getSchemeSpecificPart(), uri.getSchemeSpecificPart()) &&
                match(uriPattern.getFragment(), uri.getFragment());

    } else {
        return match(uriPattern.getScheme(), uri.getScheme()) &&
                match(uriPattern.getAuthority(), uri.getAuthority()) &&
                match(uriPattern.getQuery(), uri.getQuery()) &&
                match(uriPattern.getPath(), uri.getPath()) &&
                match(uriPattern.getFragment(), uri.getFragment());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:URIPattern.java

示例3: b

import java.net.URI; //導入方法依賴的package包/類
public static String b(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    URI i = i(str);
    if (i == null) {
        return str;
    }
    i = i.normalize();
    if (i.isOpaque()) {
        return str;
    }
    i = a(i.getScheme(), i.getAuthority(), "/", null, null);
    if (i != null) {
        return i.toString();
    }
    return str;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,代碼來源:jr.java

示例4: c

import java.net.URI; //導入方法依賴的package包/類
public static String c(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    URI i = i(str);
    if (i == null) {
        return str;
    }
    i = i.normalize();
    if (i.isOpaque()) {
        return str;
    }
    i = URIUtils.resolve(i, "./");
    if (i != null) {
        return i.toString();
    }
    return str;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,代碼來源:jr.java

示例5: rewriteURI

import java.net.URI; //導入方法依賴的package包/類
/**
 * A convenience method that creates a new {@link URI} whose scheme, host, port, path,
 * query are taken from the existing URI, dropping any fragment or user-information.
 * The path is set to "/" if not explicitly specified. The existing URI is returned
 * unmodified if it has no fragment or user-information and has a path.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 */
public static URI rewriteURI(final URI uri) throws URISyntaxException {
    Args.notNull(uri, "URI");
    if (uri.isOpaque()) {
        return uri;
    }
    final URIBuilder uribuilder = new URIBuilder(uri);
    if (uribuilder.getUserInfo() != null) {
        uribuilder.setUserInfo(null);
    }
    if (TextUtils.isEmpty(uribuilder.getPath())) {
        uribuilder.setPath("/");
    }
    if (uribuilder.getHost() != null) {
        uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ENGLISH));
    }
    uribuilder.setFragment(null);
    return uribuilder.build();
}
 
開發者ID:mozilla-mobile,項目名稱:FirefoxData-android,代碼行數:30,代碼來源:URIUtils.java

示例6: baseURL

import java.net.URI; //導入方法依賴的package包/類
/**
 * Returns the base directory or URL for the given URL. Used to implement __DIR__.
 * @param url a URL
 * @return base path or URL, or null if argument is not a hierarchical URL
 */
public static String baseURL(final URL url) {
    try {
        final URI uri = url.toURI();

        if (uri.getScheme().equals("file")) {
            final Path path = Paths.get(uri);
            final Path parent = path.getParent();
            return (parent != null) ? (parent + File.separator) : null;
        }
        if (uri.isOpaque() || uri.getPath() == null || uri.getPath().isEmpty()) {
            return null;
        }
        return uri.resolve("").toString();

    } catch (final SecurityException | URISyntaxException | IOError e) {
        return null;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:Source.java

示例7: normalize

import java.net.URI; //導入方法依賴的package包/類
public static Optional<URI> normalize(@Nonnull URI uri) {
  URI n = uri.normalize();
  String host = stripWWW(n);
  host = host == null ? null : host.toLowerCase();
  String path = normalizePath(n).getPath();
  try {
    if (n.isOpaque()) {
      return Optional.of(new URI(n.getScheme(), n.getSchemeSpecificPart(), n.getFragment()));
    } else {
      return Optional.of(new URI(n.getScheme(), null, host, n.getPort(), path, null, null));
    }
  } catch (URISyntaxException e) {
    // unlikely deviation
    throw new RuntimeException(e);
  }
}
 
開發者ID:EHRI,項目名稱:rs-aggregator,代碼行數:17,代碼來源:NormURI.java

示例8: getOwner

import java.net.URI; //導入方法依賴的package包/類
/**
 * Find the project, if any, which "owns" the given URI.
 * @param uri the URI to the file (generally on disk); must be absolute and not opaque (though {@code jar}-protocol URIs are unwrapped as a convenience)
 * @return a project which contains it, or null if there is no known project containing it
 * @throws IllegalArgumentException if the URI is relative or opaque
 */
public static Project getOwner(URI uri) {
    try {
        URL url = uri.toURL();
        if (FileUtil.isArchiveArtifact(url)) {
            url = FileUtil.getArchiveFile(url);
            if (url != null) {
                uri = url.toURI();
            }
        }
    } catch (MalformedURLException | URISyntaxException e) {
        LOG.log(Level.INFO, null, e);
    }
    if (!uri.isAbsolute() || uri.isOpaque()) {
        throw new IllegalArgumentException("Bad URI: " + uri); // NOI18N
    }
    for (FileOwnerQueryImplementation q : getInstances()) {
        Project p = q.getOwner(uri);
        if (p != null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "getOwner({0}) -> {1} from {2}", new Object[] {uri, p, q});
            }
            return p == UNOWNED ? null : p;
        }
    }
    LOG.log(Level.FINE, "getOwner({0}) -> nil", uri);
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:FileOwnerQuery.java

示例9: fromUri

import java.net.URI; //導入方法依賴的package包/類
/**
 * Converts URI to Path
 */
static Path fromUri(NetFileSystem fs, URI uri) {
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != null)
        throw new IllegalArgumentException("URI has a query component");

    // compatibility with java.io.File
    if (!uri.toString().startsWith("file:///"))
        return new File(uri).toPath();

    // transformation use raw path
    String p = uri.getRawPath();
    int len = p.length();
    if (len == 0)
        throw new IllegalArgumentException("URI path component is empty");

    // transform escaped octets and unescaped characters to bytes
    if (p.endsWith("/") && len > 1)
        p = p.substring(0, len - 1);

    return new NetPath(fs, p);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:UnixUriUtils.java

示例10: fromUri

import java.net.URI; //導入方法依賴的package包/類
/**
 * Converts given URI to a Path
 */
static WindowsPath fromUri(WindowsFileSystem fs, URI uri) {
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String path = uri.getPath();
    if (path.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // UNC
    String auth = uri.getAuthority();
    if (auth != null && !auth.equals("")) {
        String host = uri.getHost();
        if (host == null)
            throw new IllegalArgumentException("URI authority component has undefined host");
        if (uri.getUserInfo() != null)
            throw new IllegalArgumentException("URI authority component has user-info");
        if (uri.getPort() != -1)
            throw new IllegalArgumentException("URI authority component has port number");

        // IPv6 literal
        // 1. drop enclosing brackets
        // 2. replace ":" with "-"
        // 3. replace "%" with "s" (zone/scopeID delimiter)
        // 4. Append .ivp6-literal.net
        if (host.startsWith("[")) {
            host = host.substring(1, host.length()-1)
                       .replace(':', '-')
                       .replace('%', 's');
            host += IPV6_LITERAL_SUFFIX;
        }

        // reconstitute the UNC
        path = "\\\\" + host + path;
    } else {
        if ((path.length() > 2) && (path.charAt(2) == ':')) {
            // "/c:/foo" --> "c:/foo"
            path = path.substring(1);
        }
    }
    return WindowsPath.parse(fs, path);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:53,代碼來源:WindowsUriSupport.java

示例11: JdbcConnector

import java.net.URI; //導入方法依賴的package包/類
public JdbcConnector(String url) throws URISyntaxException {
    this.url = url;
    this.timezone = ApgdiffConsts.UTC;

    String host = null, user = null, pass = null, dbName = null;
    int port = -1;
    if (url.startsWith("jdbc:postgresql:")) {
        // strip jdbc:, URI doesn't understand schemas with colons
        URI uri = new URI(url.substring(5));

        if (uri.isOpaque()) {
            // special case for jdbc:postgres:database_name
            dbName = uri.getSchemeSpecificPart();
        } else {
            host = uri.getHost();
            port = uri.getPort();
            dbName = uri.getPath();
            if (dbName != null && !dbName.isEmpty()) {
                // strip leading /
                dbName = dbName.substring(1);
            }

            String query = uri.getQuery();
            if (query != null) {
                for (String param : query.split("&")) {
                    int eq = param.indexOf('=');
                    if (eq != -1) {
                        String key = param.substring(0, eq);
                        String val = param.substring(eq + 1);
                        switch (key) {
                        case "user":
                            user = val;
                            break;
                        case "password":
                            pass = val;
                            break;
                        }
                    }
                }
            }
        }
    }
    this.host = host == null ? "" : host;
    this.port = port < 1 ? ApgdiffConsts.JDBC_CONSTS.JDBC_DEFAULT_PORT : port;
    this.dbName = dbName == null ? "" : dbName;
    this.user = user == null || user.isEmpty() ? System.getProperty("user.name") : user;
    this.pass = pass == null || pass.isEmpty() ? getPgPassPassword() : pass;
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:49,代碼來源:JdbcConnector.java

示例12: fromUri

import java.net.URI; //導入方法依賴的package包/類
/**
 * Converts given URI to a Path
 */
static NetPath fromUri(NetFileSystem fs, URI uri) {
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String path = uri.getPath();
    if (path.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // UNC
    String auth = uri.getAuthority();
    if (auth != null && !auth.equals("")) {
        String host = uri.getHost();
        if (host == null)
            throw new IllegalArgumentException("URI authority component has undefined host");
        if (uri.getUserInfo() != null)
            throw new IllegalArgumentException("URI authority component has user-info");
        if (uri.getPort() != -1)
            throw new IllegalArgumentException("URI authority component has port number");

        // IPv6 literal
        // 1. drop enclosing brackets
        // 2. replace ":" with "-"
        // 3. replace "%" with "s" (zone/scopeID delimiter)
        // 4. Append .ivp6-literal.net
        if (host.startsWith("[")) {
            host = host.substring(1, host.length()-1)
                       .replace(':', '-')
                       .replace('%', 's');
            host += IPV6_LITERAL_SUFFIX;
        }

        // reconstitute the UNC
        path = "\\\\" + host + path;
    } else {
        if ((path.length() > 2) && (path.charAt(2) == ':')) {
            // "/c:/foo" --> "c:/foo"
            path = path.substring(1);
        }
    }
    return new NetPath(fs, path);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:53,代碼來源:WindowsUriSupport.java

示例13: File

import java.net.URI; //導入方法依賴的package包/類
/**
 * Creates a new {@code File} instance by converting the given
 * {@code file:} URI into an abstract pathname.
 *
 * <p> The exact form of a {@code file:} URI is system-dependent, hence
 * the transformation performed by this constructor is also
 * system-dependent.
 *
 * <p> For a given abstract pathname <i>f</i> it is guaranteed that
 *
 * <blockquote><code>
 * new File(</code><i>&nbsp;f</i><code>.{@link #toURI()
 * toURI}()).equals(</code><i>&nbsp;f</i><code>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </code></blockquote>
 *
 * so long as the original abstract pathname, the URI, and the new abstract
 * pathname are all created in (possibly different invocations of) the same
 * Java virtual machine.  This relationship typically does not hold,
 * however, when a {@code file:} URI that is created in a virtual machine
 * on one operating system is converted into an abstract pathname in a
 * virtual machine on a different operating system.
 *
 * @param  uri
 *         An absolute, hierarchical URI with a scheme equal to
 *         {@code "file"}, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If {@code uri} is {@code null}
 *
 * @throws  IllegalArgumentException
 *          If the preconditions on the parameter do not hold
 *
 * @see #toURI()
 * @see java.net.URI
 * @since 1.4
 */
public File(URI uri) {

    // Check our many preconditions
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getRawAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String p = uri.getPath();
    if (p.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // Okay, now initialize
    p = fs.fromURIPath(p);
    if (File.separatorChar != '/')
        p = p.replace('/', File.separatorChar);
    this.path = fs.normalize(p);
    this.prefixLength = fs.prefixLength(this.path);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:65,代碼來源:File.java

示例14: urlvalue

import java.net.URI; //導入方法依賴的package包/類
/**
 * Adds a URL-valued attribute.
 * @param attr the attribute name
 * @param value the attribute value, e.g. {@code "/my/module/resource.html"}
 *              or {@code "nbresloc:/my/module/resource.html"}; relative values permitted
 *              but not likely useful as base URL would be e.g. {@code "jar:...!/META-INF/"}
 * @return this builder
 * @throws LayerGenerationException in case an opaque URI is passed as {@code value}
 */
public File urlvalue(String attr, URI value) throws LayerGenerationException {
    if (value.isOpaque()) {
        throw new LayerGenerationException("Cannot use an opaque URI: " + value, originatingElement);
    }
    attrs.put(attr, new String[] {"urlvalue", value.toString()});
    return this;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:LayerBuilder.java

示例15: File

import java.net.URI; //導入方法依賴的package包/類
/**
 * Creates a new <tt>File</tt> instance by converting the given
 * <tt>file:</tt> URI into an abstract pathname.
 *
 * <p> The exact form of a <tt>file:</tt> URI is system-dependent, hence
 * the transformation performed by this constructor is also
 * system-dependent.
 *
 * <p> For a given abstract pathname <i>f</i> it is guaranteed that
 *
 * <blockquote><tt>
 * new File(</tt><i>&nbsp;f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i>&nbsp;f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </tt></blockquote>
 *
 * so long as the original abstract pathname, the URI, and the new abstract
 * pathname are all created in (possibly different invocations of) the same
 * Java virtual machine.  This relationship typically does not hold,
 * however, when a <tt>file:</tt> URI that is created in a virtual machine
 * on one operating system is converted into an abstract pathname in a
 * virtual machine on a different operating system.
 *
 * @param  uri
 *         An absolute, hierarchical URI with a scheme equal to
 *         <tt>"file"</tt>, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If <tt>uri</tt> is <tt>null</tt>
 *
 * @throws  IllegalArgumentException
 *          If the preconditions on the parameter do not hold
 *
 * @see #toURI()
 * @see java.net.URI
 * @since 1.4
 */
public File(URI uri) {

    // Check our many preconditions
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String p = uri.getPath();
    if (p.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // Okay, now initialize
    p = fs.fromURIPath(p);
    if (File.separatorChar != '/')
        p = p.replace('/', File.separatorChar);
    this.path = fs.normalize(p);
    this.prefixLength = fs.prefixLength(this.path);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:64,代碼來源:File.java


注:本文中的java.net.URI.isOpaque方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。