public FileUploadable(final File file) { this.file = file; this.fileName = FileNameUtil.getName(file.getName()); this.mimeType = null; }
/** * Gets the base name, minus the full path and extension, from a full filename. * <p> * This method will handle a file in either Unix or Windows format. * The text after the last forward or backslash and before the last dot is returned. * <pre>{@code * a/b/c.txt --> c * a.txt --> a * a/b/c --> c * a/b/c/ --> "" * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the name of the file without the path, or an empty string if none exists */ public static String getBaseName(String filename) { return removeExtension(getName(filename)); }
/** * Gets the base name, minus the full path and extension, from a full filename. * <p> * This method will handle a file in either Unix or Windows format. * The text after the last forward or backslash and before the last dot is returned. * <pre>{@code * a/b/c.txt --> c * a.txt --> a * a/b/c --> c * a/b/c/ --> "" * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the name of the file without the path, or an empty string if none exists */ public static String getBaseName(final String filename) { return removeExtension(getName(filename)); }
/** * Set content ID if it is missing. * * @return this * @see #contentId(String) */ protected EmailAttachmentBuilder setContentIdFromNameIfMissing() { if (contentId == null) { if (name != null) { contentId(FileNameUtil.getName(name)); } else { contentId(NO_NAME); } } return this; }
/** * Prepares response for various provided data. * * @param response http response * @param fileName file name, if full path then file name will be stripped, if null, will be ignored. * @param mimeType mime type with optional charset, may be <code>null</code> * @param fileSize if less then 0 it will be ignored */ public static void prepareResponse(final HttpServletResponse response, final String fileName, String mimeType, final int fileSize) { if ((mimeType == null) && (fileName != null)) { String extension = FileNameUtil.getExtension(fileName); mimeType = MimeTypes.getMimeType(extension); } if (mimeType != null) { response.setContentType(mimeType); } if (fileSize >= 0) { response.setContentLength(fileSize); } // support internationalization // See https://tools.ietf.org/html/rfc6266#section-5 for more information. if (fileName != null) { String name = FileNameUtil.getName(fileName); String encodedFileName = URLCoder.encode(name); response.setHeader(CONTENT_DISPOSITION, "attachment;filename=\"" + name + "\";filename*=utf8''" + encodedFileName); } }
public FileUploadable(final File file) { this.file = file; this.fileName = FileNameUtil.getName(file.getName()); this.mimeType = null; }
/** * Gets the base name, minus the full path and extension, from a full filename. * <p> * This method will handle a file in either Unix or Windows format. * The text after the last forward or backslash and before the last dot is returned. * <pre>{@code * a/b/c.txt --> c * a.txt --> a * a/b/c --> c * a/b/c/ --> "" * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the name of the file without the path, or an empty string if none exists */ public static String getBaseName(final String filename) { return removeExtension(getName(filename)); }
/** * Set content ID if it is missing. * * @return this * @see #contentId(String) */ protected EmailAttachmentBuilder setContentIdFromNameIfMissing() { if (contentId == null) { if (name != null) { contentId(FileNameUtil.getName(name)); } else { contentId(NO_NAME); } } return this; }