Java URI to toString(URI uri)

Here you can find the source of toString(URI uri)

Description

Creates a String from a URI, the URI can be relative or absolute, the URI is decoded.

License

Open Source License

Parameter

Parameter Description
uri the URI to return the string representation for.

Return

a string representation of the URI.

Declaration

public static String toString(URI uri) 

Method Source Code

//package com.java2s;

import java.net.URI;

public class Main {
    /**/*from ww  w  .j a  va2s  . c om*/
     * Creates a String from a URI, the URI can be relative or absolute, the URI is decoded.
     *
     * TODO Why can't I just return uri.toString()???
     *
     * @param uri the URI to return the string representation for.
     * @return a string representation of the URI.
     */
    public static String toString(URI uri) {
        StringBuffer buffer = new StringBuffer();
        if (uri.getScheme() != null) {
            buffer.append(uri.getScheme());
            buffer.append(":");
        }
        buffer.append(uri.getSchemeSpecificPart());
        if (uri.getFragment() != null) {
            buffer.append("#");
            buffer.append(uri.getFragment());
        }
        return buffer.toString();
    }
}

Related

  1. toNdnUri(String channelName)
  2. toPackageTokens(String uri)
  3. toRelativeURI(URI uri)
  4. toRepositoryItemUri(String uriString)
  5. toString(URI pathUri)
  6. toStringList(List list)
  7. toStringSet(Collection uris)
  8. toUnencodedString(URI uri)
  9. URItoString(URI uri)