Gets file path extension as opt.

@param path the path
@return the file path extension as opt
170122
public static Optional<String> getFilePathExtensionAsOpt(Path path) {
		return JMOptional
				.getNullableAndFilteredOptional(path, RegularFileFilter)
				.map(JMPath::getLastName).map(JMString::getExtension)
				.filter(getIsEmpty().negate());
	}
197270
public static String removeExtension(String path) throws IllegalArgumentException
  {
    Params.notNull(path, "Path");
    int extensionIndex = path.lastIndexOf('.');
    return extensionIndex != -1 ? path.substring(0, extensionIndex) : path;
  }
559435
public static String compactPath(String path) {
        if (path == null || path.length() == 0)
            return path;

        int state = 0;
        int end = path.length();
        int i = 0;

        loop:
        while (i < end) {
            char c = path.charAt(i);
            switch (c) {
                case '?':
                    return path;
                case '/':
                    state++;
                    if (state == 2)
                        break loop;
                    break;
                default:
                    state = 0;
            }
            i++;
        }

        if (state < 2)
            return path;

        StringBuilder buf = new StringBuilder(path.length());
        buf.append(path, 0, i);

        loop2:
        while (i < end) {
            char c = path.charAt(i);
            switch (c) {
                case '?':
                    buf.append(path, i, end);
                    break loop2;
                case '/':
                    if (state++ == 0)
                        buf.append(c);
                    break;
                default:
                    state = 0;
                    buf.append(c);
            }
            i++;
        }

        return buf.toString();
    }
513103
@Override
	public boolean matchPath(String path) {

		boolean match = false;
		if (StringUtils.isNotEmpty(path)) {
			match = path.endsWith(suffix);
		}
		return match;
	}
1082372
public static final String posixString(Path path)
    {
        String prefix = path.isAbsolute() ? "/" : "";
        String suffix = Files.isDirectory(path) ? "/" : "";
        return StreamSupport.stream(path.spliterator(), false)
                .map((p)->p.toString())
                .collect(Collectors.joining("/", prefix, suffix));
    }
423552
public static String getClassNameForClassFile(String rootDir, String path) {
        path = path.replace("/", ".");
        path = path.replace('\\', '.');
        path = path.substring(0, path.length() - CLASS_EXTENSION.length());
        if (rootDir != null) {
            path = path.substring(rootDir.length());
        }
        return path;
    }
798133
public static String getNodeFromPath(String path)
    {
        PathUtils.validatePath(path);
        int i = path.lastIndexOf(PATH_SEPARATOR);
        if ( i < 0 )
        {
            return path;
        }
        if ( (i + 1) >= path.length() )
        {
            return "";
        }
        return path.substring(i + 1);
    }
1194366
@Nonnull
    public static Path getApprovalPath(Path filePath) {
        Pre.notNull(filePath, "filePath");

        String s = filePath.toString();
        int extensionIndex = s.lastIndexOf('.');

        if (extensionIndex == -1) {
            return Paths.get(s + FOR_APPROVAL_EXTENSION);
        }

        int lastPartOfPath = s.lastIndexOf('/');
        if (lastPartOfPath != -1 && lastPartOfPath > extensionIndex) {
            //there was no extension and the directory contains dots.
            return Paths.get(s + FOR_APPROVAL_EXTENSION);
        }

        String firstPart = s.substring(0, extensionIndex);
        String extension = s.substring(extensionIndex);

        return Paths.get(firstPart + FOR_APPROVAL_EXTENSION + extension);

    }
118762
public static UnixPath getPath(boolean permitEmptyComponents, String path) {
    if (path.isEmpty()) {
      return EMPTY_PATH;
    } else if (isRootInternal(path)) {
      return ROOT_PATH;
    } else {
      return new UnixPath(permitEmptyComponents, path);
    }
  }
9888
public static String getFilename(String path) {
        //The filename is after the last slash
        final int index = path != null ? path.lastIndexOf("/") : -1;
        if (index == -1) {
            IOException ioe = new IOException(TraceNLS.getFormattedMessage(FileTransferHelper.class,
                                                                           APIConstants.TRACE_BUNDLE_FILE_TRANSFER,
                                                                           "PATH_NOT_VALID",
                                                                           new String[] { path },
                                                                           "CWWKX0127E: The path " + path + " is not valid."));
            throw ErrorHelper.createRESTHandlerJsonException(ioe, null, APIConstants.STATUS_BAD_REQUEST);
        }

        return path.substring(index + 1);
    }
110737
private static String getUpType(String path) {
        if (path == null || !path.startsWith("/")) {
            return "";
        }
        if ("/".equals(path)) {
            return "form";
        }
        int l = path.indexOf('/', 1);
        if (l < 1) {
            return "";
        }
        String m = path.substring(1, l);
        switch (m) {
            case "mkblk":
                return "mkblk";
            case "bput":
                return "bput";
            case "mkfile":
                return "mkfile";
            case "put":
                return "put";
            default:
                return "";
        }
    }
1063232
private String getSlashyPath(final String path) {
        String changedPath = path;
        if (File.separatorChar != '/')
            changedPath = changedPath.replace(File.separatorChar, '/');

        return changedPath;
    }
1230338
private static String filePathToKey(String path) {

        try {
            return FileUtil.getDefaultInstance().canonicalPath(path);
        } catch (Exception e) {
            return path;
        }
    }
397614
public static @NonNull String[] splitPath(String path) {
		@NonNull String[] split = new @NonNull String[] { "", "", "" };
		int baseIndex = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
		String fileName;

		if (baseIndex > 0) {
			split[0] = path.substring(0, baseIndex);
			fileName = path.substring(baseIndex + 1);
		} else if (baseIndex == 0) {
			split[0] = path.substring(0, baseIndex + 1);
			fileName = path.substring(baseIndex + 1);
		} else {
			fileName = path;
		}

		int extIndex = fileName.lastIndexOf('.');

		if (extIndex > 0) {
			split[1] = fileName.substring(0, extIndex);
			split[2] = fileName.substring(extIndex + 1);
		} else {
			split[1] = fileName;
		}
		return split;
	}
1280623
public static String filepath2URI(String path){
        // return null if path is null.
        if (path == null)
            return null;

        char separator = java.io.File.separatorChar;
        path = path.replace(separator, '/');

        int len = path.length(), ch;
        StringBuilder buffer = new StringBuilder(len*3);
        buffer.append("file://");
        // change C:/blah to /C:/blah
        if (len >= 2 && path.charAt(1) == ':') {
            ch = Character.toUpperCase(path.charAt(0));
            if (ch >= 'A' && ch <= 'Z') {
                buffer.append('/');
            }
        }

        // for each character in the path
        int i = 0;
        for (; i < len; i++) {
            ch = path.charAt(i);
            // if it's not an ASCII character, break here, and use UTF-8 encoding
            if (ch >= 128)
                break;
            if (gNeedEscaping[ch]) {
                buffer.append('%');
                buffer.append(gAfterEscaping1[ch]);
                buffer.append(gAfterEscaping2[ch]);
                // record the fact that it's escaped
            }
            else {
                buffer.append((char)ch);
            }
        }

        // we saw some non-ascii character
        if (i < len) {
            // get UTF-8 bytes for the remaining sub-string
            byte[] bytes = null;
            byte b;
            try {
                bytes = path.substring(i).getBytes("UTF-8");
            } catch (java.io.UnsupportedEncodingException e) {
                // should never happen
                return path;
            }
            len = bytes.length;

            // for each byte
            for (i = 0; i < len; i++) {
                b = bytes[i];
                // for non-ascii character: make it positive, then escape
                if (b < 0) {
                    ch = b + 256;
                    buffer.append('%');
                    buffer.append(gHexChs[ch >> 4]);
                    buffer.append(gHexChs[ch & 0xf]);
                }
                else if (gNeedEscaping[b]) {
                    buffer.append('%');
                    buffer.append(gAfterEscaping1[b]);
                    buffer.append(gAfterEscaping2[b]);
                }
                else {
                    buffer.append((char)b);
                }
            }
        }

        return buffer.toString();
    }
34748
private static String __getExtension(String path) {

        for (int i = path.length() - 1; i >= 0; i--) {
            if (path.charAt(i) == '.') {
                return path.substring(i + 1);
            }
        }

        return "";
    }
852170
protected String findClasspathFile(final String path) throws IOException {
        if (path == null){
            return null;
        }
        final File file = new File(path);
        if (file.exists()){
            return file.getAbsolutePath();
        }
        return createTmpFile(path).getAbsolutePath();
    }