// // Constructor // public Uri(string uriString, bool dontEscape, UriKind uriKind) { ThrowHelper.ThrowIfNull(uriString); if (uriString == "") { throw new UriFormatException("empty URI"); } if (!dontEscape) { if (uriKind != UriKind.Relative) { uriString = java.net.URLEncoder.encode(uriString, "UTF-8"); } } try { JavaURI = new java.net.URI(uriString); } catch (java.net.URISyntaxException e) { throw new UriFormatException(e.getMessage(), e); } if (uriKind == UriKind.Absolute) { if (!JavaURI.isAbsolute()) { throw new UriFormatException("relative URI for " + uriKind); } } else if (uriKind == UriKind.Relative) { if (JavaURI.isAbsolute()) { throw new UriFormatException("absolute URI for " + uriKind); } } else if (uriKind != UriKind.RelativeOrAbsolute) { throw new ArgumentException(); } }
private static void checkURI(java.net.URI uri) { if (!uri.isAbsolute()) { throw new System.ArgumentException("URI is not absolute: " + uri); } else { if (!uri.getRawSchemeSpecificPart().StartsWith("/")) { throw new System.ArgumentException("URI is not hierarchical: " + uri); } } if (!"file".Equals(uri.getScheme())) { throw new System.ArgumentException("Expected file scheme in URI: " + uri); } string rawPath = uri.getRawPath(); if (rawPath == null || string.IsNullOrEmpty(rawPath)) { throw new System.ArgumentException("Expected non-empty path in URI: " + uri); } if (uri.getRawAuthority() != null) { throw new System.ArgumentException("Found authority in URI: " + uri); } if (uri.getRawQuery() != null) { throw new System.ArgumentException("Found query in URI: " + uri); } if (uri.getRawFragment() != null) { throw new System.ArgumentException("Found fragment in URI: " + uri); } }