List of utility methods to do URI to File Name
String | getFileName(URI path) get File Name return getFileName(path.normalize().getPath());
|
String | getFileName(URI uri) get File Name String path[] = uri.toString().split("/"); return path[path.length - 1]; |
String | getFileName(URI uri) Extract the file-name portion of a URI. String path = uri.toString(); int lastSlashIndex = path.lastIndexOf("/"); return path.substring(lastSlashIndex + 1, path.length()); |
String | getFileName(URI uri) get File Name if (uri == null) { return null; String[] splits = uri.getPath().split(File.separator); return splits[splits.length - 1]; |
String | getFileName(URI uri) get File Name if (uri == null) { return null; String uriPath = uri.getPath(); IPath path = Path.fromPortableString(uriPath); if (path == null) { return null; return path.lastSegment(); |
String | getFileNameFromURI(final URI resourceAddress, final boolean usePathStyleUris) Gets the file name from the URI. final String[] pathSegments = resourceAddress.getRawPath().split("/"); final int shareIndex = usePathStyleUris ? 2 : 1; if (pathSegments.length - 1 <= shareIndex) { throw new IllegalArgumentException(String.format("Invalid file address '%s'.", resourceAddress)); } else { return pathSegments[pathSegments.length - 1]; |
String | getFilenameFromURI(URI uri, boolean preserveExtension) get Filename From URI int slashIndex = uri.toString().lastIndexOf('/'); int dotIndex = uri.toString().lastIndexOf('.'); String filenameWithoutExtension = null; if (dotIndex == -1 || preserveExtension) { filenameWithoutExtension = uri.toString().substring(slashIndex + 1); } else { filenameWithoutExtension = uri.toString().substring(slashIndex + 1, dotIndex); return filenameWithoutExtension; |
String | getFilePart(String uri) get File Part try { URI u = URI.create(uri); uri = u.getPath(); } catch (Exception e) { return "http://invalid/uri/"; int begin = uri.lastIndexOf("/"); int end = uri.lastIndexOf("."); ... |
URI | getFileSystemURI(URI uri) Returns the filesystem URI. if (uri == null) { return uri; try { return new URI(uri.getScheme(), uri.getAuthority(), null, null, null); } catch (URISyntaxException x) { throw new IllegalArgumentException(x.getMessage(), x); |