/** * Returns the index of the last extension separator character, which is a dot. * <p> * This method also checks that there is no directory separator after the last dot. * To do this it uses {@link #indexOfLastSeparator(String)} which will * handle a file in either Unix or Windows format. * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to find the last path separator in, null returns -1 * @return the index of the last separator character, or -1 if there * is no such character */ public static int indexOfExtension(String filename) { if (filename == null) { return -1; } int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR); int lastSeparator = indexOfLastSeparator(filename); return (lastSeparator > extensionPos ? -1 : extensionPos); }
/** * Gets the name minus the path 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 is returned. * <pre>{@code * a/b/c.txt --> c.txt * a.txt --> a.txt * 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 getName(String filename) { if (filename == null) { return null; } int index = indexOfLastSeparator(filename); return filename.substring(index + 1); }
/** * Returns the index of the last extension separator character, which is a dot. * <p> * This method also checks that there is no directory separator after the last dot. * To do this it uses {@link #indexOfLastSeparator(String)} which will * handle a file in either Unix or Windows format. * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to find the last path separator in, null returns -1 * @return the index of the last separator character, or -1 if there * is no such character */ public static int indexOfExtension(final String filename) { if (filename == null) { return -1; } int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR); int lastSeparator = indexOfLastSeparator(filename); return (lastSeparator > extensionPos ? -1 : extensionPos); }
/** * Gets the name minus the path 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 is returned. * <pre>{@code * a/b/c.txt --> c.txt * a.txt --> a.txt * 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 getName(final String filename) { if (filename == null) { return null; } int index = indexOfLastSeparator(filename); return filename.substring(index + 1); }
/** * Does the work of getting the path. * * @param filename the filename * @param separatorAdd 0 to omit the end separator, 1 to return it * @return the path */ private static String doGetPath(String filename, int separatorAdd) { if (filename == null) { return null; } int prefix = getPrefixLength(filename); if (prefix < 0) { return null; } int index = indexOfLastSeparator(filename); int endIndex = index + separatorAdd; if (prefix >= filename.length() || index < 0 || prefix >= endIndex) { return StringPool.EMPTY; } return filename.substring(prefix, endIndex); }
/** * Does the work of getting the path. * * @param filename the filename * @param separatorAdd 0 to omit the end separator, 1 to return it * @return the path */ private static String doGetPath(final String filename, final int separatorAdd) { if (filename == null) { return null; } int prefix = getPrefixLength(filename); if (prefix < 0) { return null; } int index = indexOfLastSeparator(filename); int endIndex = index + separatorAdd; if (prefix >= filename.length() || index < 0 || prefix >= endIndex) { return StringPool.EMPTY; } return filename.substring(prefix, endIndex); }
prefix = StringPool.EMPTY; int lastSeparatorIndex = indexOfLastSeparator(filename); int lastExtensionIndex = indexOfExtension(filename);
int index = indexOfLastSeparator(filename); if (index < 0) { return filename.substring(0, prefix);
prefix = StringPool.EMPTY; int lastSeparatorIndex = indexOfLastSeparator(filename); int lastExtensionIndex = indexOfExtension(filename);
int index = indexOfLastSeparator(filename); if (index < 0) { return filename.substring(0, prefix);
FileUploadHeader(final String dataHeader) { this.dataHeader = dataHeader; isFile = dataHeader.indexOf("filename") > 0; formFieldName = getDataFieldValue(dataHeader, "name"); if (isFile) { formFileName = getDataFieldValue(dataHeader, "filename"); if (formFileName == null) { return; } if (formFileName.length() == 0) { path = StringPool.EMPTY; fileName = StringPool.EMPTY; } int ls = FileNameUtil.indexOfLastSeparator(formFileName); if (ls == -1) { path = StringPool.EMPTY; fileName = formFileName; } else { path = formFileName.substring(0, ls); fileName = formFileName.substring(ls + 1); } if (fileName.length() > 0) { this.contentType = getContentType(dataHeader); mimeType = getMimeType(contentType); mimeSubtype = getMimeSubtype(contentType); contentDisposition = getContentDisposition(dataHeader); } } }
/** * Returns the index of the last extension separator character, which is a dot. * <p> * This method also checks that there is no directory separator after the last dot. * To do this it uses {@link #indexOfLastSeparator(String)} which will * handle a file in either Unix or Windows format. * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to find the last path separator in, null returns -1 * @return the index of the last separator character, or -1 if there * is no such character */ public static int indexOfExtension(final String filename) { if (filename == null) { return -1; } int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR); int lastSeparator = indexOfLastSeparator(filename); return (lastSeparator > extensionPos ? -1 : extensionPos); }
/** * Gets the name minus the path 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 is returned. * <pre>{@code * a/b/c.txt --> c.txt * a.txt --> a.txt * 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 getName(final String filename) { if (filename == null) { return null; } int index = indexOfLastSeparator(filename); return filename.substring(index + 1); }
/** * Does the work of getting the path. * * @param filename the filename * @param separatorAdd 0 to omit the end separator, 1 to return it * @return the path */ private static String doGetPath(final String filename, final int separatorAdd) { if (filename == null) { return null; } int prefix = getPrefixLength(filename); if (prefix < 0) { return null; } int index = indexOfLastSeparator(filename); int endIndex = index + separatorAdd; if (prefix >= filename.length() || index < 0 || prefix >= endIndex) { return StringPool.EMPTY; } return filename.substring(prefix, endIndex); }
prefix = StringPool.EMPTY; int lastSeparatorIndex = indexOfLastSeparator(filename); int lastExtensionIndex = indexOfExtension(filename);
int index = indexOfLastSeparator(filename); if (index < 0) { return filename.substring(0, prefix);
FileUploadHeader(final String dataHeader) { this.dataHeader = dataHeader; isFile = dataHeader.indexOf("filename") > 0; formFieldName = getDataFieldValue(dataHeader, "name"); if (isFile) { formFileName = getDataFieldValue(dataHeader, "filename"); if (formFileName == null) { return; } if (formFileName.length() == 0) { path = StringPool.EMPTY; fileName = StringPool.EMPTY; } int ls = FileNameUtil.indexOfLastSeparator(formFileName); if (ls == -1) { path = StringPool.EMPTY; fileName = formFileName; } else { path = formFileName.substring(0, ls); fileName = formFileName.substring(ls + 1); } if (fileName.length() > 0) { this.contentType = getContentType(dataHeader); mimeType = getMimeType(contentType); mimeSubtype = getMimeSubtype(contentType); contentDisposition = getContentDisposition(dataHeader); } } }