Java URI Create getURIName(String forwardSlashPath)

Here you can find the source of getURIName(String forwardSlashPath)

Description

Path is parsed using '/' as separator.

License

Open Source License

Parameter

Parameter Description
forwardSlashPath whose path to get name of.

Return

name of file or directory.

Declaration

public static String getURIName(String forwardSlashPath) 

Method Source Code


//package com.java2s;

import java.net.URI;

public class Main {
    /**//from   w w  w .ja v a 2  s.  com
     * Path is parsed using '/' as separator.
     * 
     * @param forwardSlashPath
     *            whose path to get name of.
     * @return name of file or directory.
     */
    public static String getURIName(String forwardSlashPath) {
        if (forwardSlashPath == null)
            return null;
        int end = forwardSlashPath.length();
        if (end == 0)
            return "";
        if (forwardSlashPath.charAt(end - 1) == '/')
            end = end - 1;
        if (end == 0)
            return "/";
        int index = forwardSlashPath.substring(0, end).lastIndexOf('/');
        return forwardSlashPath.substring(index + 1, end);
    }

    /**
     * Derives name from uri; calls overloaded method. the uri path is parsed
     * using '/' as separator.
     * 
     * @param uri
     *            whose path to get name of.
     * @return name of file or directory.
     */
    public static String getURIName(URI uri) {
        if (uri == null)
            return null;
        return getURIName(uri.getPath());
    }
}

Related

  1. getUriByEndpoint(String endpoint)
  2. getURIFilename(final String s)
  3. getURIFromEncodedString(String unencoded)
  4. getURIFromPath(String fileOrURI)
  5. getURIFromPath(String path)
  6. getURIName(URI uri)
  7. getURIParameterValue(URI uri, String name, String defVal)
  8. getURIs(final Object[] objs)
  9. getUriScheme(String address)