Refine search
/** * Checks the correctness of the string representation of URI name. * The correctness is checked as pointed out in RFC 3280 p. 34. */ public static void checkURI(String uri) throws IOException { try { URI ur = new URI(uri); if (ur.getScheme() == null || ur.getRawSchemeSpecificPart().isEmpty()) { throw new IOException("No scheme or scheme-specific-part in uniformResourceIdentifier: " + uri); } if (!ur.isAbsolute()) { throw new IOException("Relative uniformResourceIdentifier: " + uri); } } catch (URISyntaxException e) { throw (IOException) new IOException("Bad representation of uniformResourceIdentifier: " + uri).initCause(e); } }
String scheme = uri.getScheme(); if (scheme == null) return null; return null; if(uri.getRawSchemeSpecificPart().contains("%2B")) { schemeSpecific = schemeSpecific.replace("+", "%2B");
/** * Creates a URI with the given query, removing an previous query value from the given URI. * * @param uri The source URI whose existing query is replaced with the newly supplied one. * @param query The new URI query string that should be appended to the given URI. * @return a new URI that is a combination of the original URI and the given query string. * @throws java.net.URISyntaxException */ public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException { String schemeSpecificPart = uri.getRawSchemeSpecificPart(); // strip existing query if any int questionMark = schemeSpecificPart.lastIndexOf("?"); // make sure question mark is not within parentheses if (questionMark < schemeSpecificPart.lastIndexOf(")")) { questionMark = -1; } if (questionMark > 0) { schemeSpecificPart = schemeSpecificPart.substring(0, questionMark); } if (query != null && query.length() > 0) { schemeSpecificPart += "?" + query; } return new URI(uri.getScheme(), schemeSpecificPart, uri.getFragment()); }
/** * Creates a URI with the given query, removing an previous query value from the given URI. * * @param uri * The source URI whose existing query is replaced with the newly supplied one. * @param query * The new URI query string that should be appended to the given URI. * * @return a new URI that is a combination of the original URI and the given query string. * @throws URISyntaxException */ public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException { String schemeSpecificPart = uri.getRawSchemeSpecificPart(); // strip existing query if any int questionMark = schemeSpecificPart.lastIndexOf("?"); // make sure question mark is not within parentheses if (questionMark < schemeSpecificPart.lastIndexOf(")")) { questionMark = -1; } if (questionMark > 0) { schemeSpecificPart = schemeSpecificPart.substring(0, questionMark); } if (query != null && query.length() > 0) { schemeSpecificPart += "?" + query; } return new URI(uri.getScheme(), schemeSpecificPart, uri.getFragment()); }
private static void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException("URI is not absolute: " + uri); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException("URI is not hierarchical: " + uri); } if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } String rawPath = uri.getRawPath(); if (rawPath == null || rawPath.isEmpty()) { throw new IllegalArgumentException("Expected non-empty path in URI: " + uri); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException("Found authority in URI: " + uri); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException("Found query in URI: " + uri); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException("Found fragment in URI: " + uri); } }
this.scheme = uri.getScheme(); if (uri.isOpaque()) { this.ssp = uri.getRawSchemeSpecificPart(); resetHierarchicalComponents();
b.append(uri.getScheme()); if (uriSchemeAuthority != null) { b.append('.').append(uriSchemeAuthority); b.append(':').append(uri.getRawSchemeSpecificPart()); for (Map.Entry<String, List<AttributeValue>> entry : attributes.entrySet()) { b.append(';').append(entry.getKey());
/** * Given a composite URI, parse the individual URI elements contained within that URI and return * a CompositeData instance that contains the parsed URI values. * * @param uri The target URI that should be parsed. * @return a new CompositeData instance representing the parsed composite URI. * @throws java.net.URISyntaxException */ public static CompositeData parseComposite(URI uri) throws URISyntaxException { CompositeData rc = new CompositeData(); rc.scheme = uri.getScheme(); String ssp = stripPrefix(uri.getRawSchemeSpecificPart().trim(), "//").trim(); parseComposite(uri, rc, ssp); rc.fragment = uri.getFragment(); return rc; }
private void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException(); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException(); } String temp = uri.getScheme(); if (temp == null || !temp.equals("file")) { throw new IllegalArgumentException(); } temp = uri.getRawPath(); if (temp == null || temp.length() == 0) { throw new IllegalArgumentException(); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException(); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException(); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException(); } }
/** * Given a composite URI, parse the individual URI elements contained within that URI and return * a CompsoteData instance that contains the parsed URI values. * * @param uri * The target URI that should be parsed. * * @return a new CompsiteData instance representing the parsed composite URI. * @throws URISyntaxException */ public static CompositeData parseComposite(URI uri) throws URISyntaxException { CompositeData rc = new CompositeData(); rc.scheme = uri.getScheme(); String ssp = stripPrefix(uri.getRawSchemeSpecificPart().trim(), "//").trim(); parseComposite(uri, rc, ssp); rc.fragment = uri.getFragment(); return rc; }
scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart(); return this; if (uri.getScheme() == null) { if (ssp != null) { if (uri.getRawSchemeSpecificPart() != null) { ssp = uri.getRawSchemeSpecificPart(); return this; scheme = uri.getScheme();
scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart(); return this; if (uri.getScheme() == null) { if (ssp != null) { if (uri.getRawSchemeSpecificPart() != null) { ssp = uri.getRawSchemeSpecificPart(); return this; scheme = uri.getScheme();
scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart(); return this; if (uri.getScheme() == null) { if (ssp != null) { if (uri.getRawSchemeSpecificPart() != null) { ssp = uri.getRawSchemeSpecificPart(); return this; scheme = uri.getScheme();
this.scheme = uri.getScheme(); if (uri.isOpaque()) { this.ssp = uri.getRawSchemeSpecificPart(); resetHierarchicalComponents();
public static URI getJarSource(URI uri) { try { if (!"jar".equals(uri.getScheme())) return uri; // Get SSP (retaining encoded form) String s = uri.getRawSchemeSpecificPart(); int bang_slash = s.indexOf("!/"); if (bang_slash>=0) s=s.substring(0,bang_slash); return new URI(s); } catch(URISyntaxException e) { throw new IllegalArgumentException(e); } }
scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart(); return this; if (uri.getScheme() == null) if (uri.getRawSchemeSpecificPart() != null) ssp = uri.getRawSchemeSpecificPart(); return this; scheme = uri.getScheme();
/** * Determines whether the given URI is an {@value URIs#INFO_SCHEME} scheme URI with the given namespace. * @param uri The URI to check. * @param infoNamespace The info namespace to match for the URI. * @return The <code>true</code> if the given URI has a scheme of {@value URIs#INFO_SCHEME} and has the indicated info namespace. * @throws NullPointerException if the given URI and/or info namespace is <code>null</code>. */ public static final boolean isInfoNamespace(final URI uri, final String infoNamespace) { return INFO_SCHEME.equals(uri.getScheme()) && uri.getRawSchemeSpecificPart().startsWith(infoNamespace + INFO_SCHEME_NAMESPACE_DELIMITER); //check for the info scheme and the info namespace }
/** * Determines whether the given URI is a UNC file path URI in the form <code>file:////server/file.ext</code>. * <p> * Strangly, the Java URI form of a UNC path will contain a path prefixed with <code>//</code>, but the entire scheme-specific part will be prefixed with * <code>////</code>. * </p> * @param uri The URI to test. * @return <code>true</code> if the given URI has a scheme of {@value #FILE_SCHEME} and its scheme-specific part begins with four slashes. * @see #WINDOWS_UNC_PATH_URI_SSP_PREFIX */ public static boolean isUNCFileURI(final URI uri) { return FILE_SCHEME.equals(uri.getScheme()) && uri.getRawSchemeSpecificPart().startsWith(WINDOWS_UNC_PATH_URI_SSP_PREFIX); }
public static void main(final String[] args) throws Exception { // get URI of class String clazz = "String.class"; URI resourceURI = String.class.getResource(clazz).toURI(); System.out.println(resourceURI.getScheme()); System.out.println(resourceURI.getRawSchemeSpecificPart()); URI fileURI = new URI(resourceURI.getRawSchemeSpecificPart()); System.out.println(fileURI.getScheme()); System.out.println(fileURI.getRawSchemeSpecificPart()); Path path = Paths.get(fileURI); System.out.println(path); System.out.println(path.getParent()); }
public static URI getJarSource(URI uri) { try { if (!"jar".equals(uri.getScheme())) return uri; // Get SSP (retaining encoded form) String s = uri.getRawSchemeSpecificPart(); int bang_slash = s.indexOf("!/"); if (bang_slash >= 0) s = s.substring(0, bang_slash); return new URI(s); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }