/** * Indicates whether requested file path is an image. This is done by checking Mimetype of file * via {@link MimeTypes} class, and by comparing file extension to a static list of extensions * known to be videos. * * @param file File path * @return {@code true} if file is video, {@code false} if not. */ public static boolean isVideoFile(String path) { if (MimeTypes.Default != null) if (MimeTypes.Default.getMimeType(path).startsWith("video/")) return true; String ext = path.substring(path.lastIndexOf(".") + 1); if (ext.equalsIgnoreCase("mp4") || ext.equalsIgnoreCase("3gp") || ext.equalsIgnoreCase("avi") || ext.equalsIgnoreCase("webm") || ext.equalsIgnoreCase("m4v")) return true; return false; }
/** * Indicates whether requested file path is an image. This is done by comparing file extension to * a static list of extensions known to be images. * * @param file File path * @return {@code true} if file is image, {@code false} if not. */ public static boolean isImageFile(String file) { String ext = file.substring(file.lastIndexOf(".") + 1); if (MimeTypes.Default != null) if (MimeTypes.Default.getMimeType(file).startsWith("image/")) return true; if (ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg") || ext.equalsIgnoreCase("gif") || ext.equalsIgnoreCase("tiff") || ext.equalsIgnoreCase("tif")) return true; return false; }
/** * Indicates whether requested file path is "text". This is done by comparing file extension to a * static list of extensions known to be text. If the file has no file extension, it is also * considered to be text. * * @param file File path * @return {@code true} if file is text, {@code false} if not. */ public static boolean isTextFile(String file) { if (file == null) return false; if (file.indexOf(".") == -1) return true; file = file.substring(file.lastIndexOf("/") + 1); String ext = file.substring(file.lastIndexOf(".") + 1); if (MimeTypes.Default != null) if (MimeTypes.Default.getMimeType(file).startsWith("text/")) return true; if (ext.equalsIgnoreCase("txt") || ext.equalsIgnoreCase("php") || ext.equalsIgnoreCase("html") || ext.equalsIgnoreCase("htm") || ext.equalsIgnoreCase("xml")) return true; return false; }
/** * Indicates mimetype of file. * * @see MimeTypes */ public String getMimeType() { if (isDirectory()) return "x-directory/normal"; if (MimeTypes.Default != null) return MimeTypes.Default.getMimeType(getPath()); return "*/*"; }