Java Utililty Methods URI to

List of utility methods to do URI to

Description

The list of methods to do URI to are organized into topic(s).

Method

FiletoFile(URI uri)
Creates a File from a URI, the URI can be relative or absolute, this method returns only a file for the Scheme Specific Part.
return new File((File) null, uri.getSchemeSpecificPart());
FiletoFile(URI uri)
Returns the URI as a local file, or null if the given URI does not represent a local file.
try {
    if (!SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) {
        return null;
    return new File(uri);
} catch (IllegalArgumentException e) {
    String path = uri.getPath();
    if (path == null) {
...
StringtoFileURI(File file)
to File URI
URI uri = file.toURI();
String uriString = uri.toASCIIString();
return uriString.replaceAll("^file:/", "file:///");
URItoFileURI(String path)
to File URI
if (null == path) {
    return null;
} else if (path.startsWith("file:")) {
    return URI.create(path);
} else {
    return new File(path).toURI();
StringTokenizertokenizeBase(URI uri)
tokenize Base
String scheme = uri.getSchemeSpecificPart();
int index = scheme.lastIndexOf("/");
if (index != -1) {
    scheme = scheme.substring(0, index + 1);
return new StringTokenizer(scheme, "/");
StringtoName(URI uri)
Returns the name of URI for hint.
if (uri == null) {
    throw new IllegalArgumentException("uri must not be null"); 
String path = uri.getSchemeSpecificPart();
if (path == null) {
    return uri.toString();
String name = path.substring(path.lastIndexOf('/') + 1);
...
URItoNdnUri(String channelName)
Convenience method for generating a file URI.
try {
    return new URI("ndn", channelName, null);
} catch (URISyntaxException e) {
    throw new IllegalArgumentException("Invalid channel name: " + channelName);
String[]toPackageTokens(String uri)
Tokenizes the given URI as an array of names suitable to be used as a UML package hierarchy.
List<String> list = new ArrayList<String>();
try {
    java.net.URL url = new java.net.URL(uri);
    String[] authority = url.getAuthority().split("\\.");
    for (int i = authority.length - 1; i >= 0; i--)
        if (authority[i] != null && authority[i].trim().length() > 0)
            list.add(authority[i]);
    if (url.getPath() != null) {
...
StringtoRelativeURI(URI uri)
to Relative URI
StringBuilder sb = new StringBuilder();
if (uri.getRawPath() != null)
    sb.append(uri.getRawPath());
if (uri.getRawQuery() != null) {
    sb.append('?');
    sb.append(uri.getRawQuery());
if (uri.getRawFragment() != null) {
...
URItoRepositoryItemUri(String uriString)
Converts the given string to a URI.
URI uri = new URI(uriString);
if ((uri.getScheme() == null) || !uri.getScheme().equals("otm")) {
    throw new URISyntaxException(uriString, "The OTM repository URI provided is not valid.", 0);
if (uri.getAuthority() == null) {
    throw new URISyntaxException(uriString,
            "All OTM repository URI's must specify a repository ID as the authority.", 6);
if (uri.getPath() == null) {
    throw new URISyntaxException(uriString,
            "All OTM repository URI's must specify the filename of a managed resource..",
            (uriString.length() - 1));
return uri;