org.apache.commons.fileupload.InvalidFileNameException Java Examples

The following examples show how to use org.apache.commons.fileupload.InvalidFileNameException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Streams.java    From Mars-Java with MIT License 6 votes vote down vote up
/**
 * Checks, whether the given file name is valid in the sense,
 * that it doesn't contain any NUL characters. If the file name
 * is valid, it will be returned without any modifications. Otherwise,
 * an {@link InvalidFileNameException} is raised.
 *
 * @param fileName The file name to check
 * @return Unmodified file name, if valid.
 * @throws InvalidFileNameException The file name was found to be invalid.
 */
public static String checkFileName(String fileName) {
    if (fileName != null  &&  fileName.indexOf('\u0000') != -1) {
        // pFileName.replace("\u0000", "\\0")
        final StringBuilder sb = new StringBuilder();
        for (int i = 0;  i < fileName.length();  i++) {
            char c = fileName.charAt(i);
            switch (c) {
                case 0:
                    sb.append("\\0");
                    break;
                default:
                    sb.append(c);
                    break;
            }
        }
        throw new InvalidFileNameException(fileName,
                "Invalid file name: " + sb);
    }
    return fileName;
}
 
Example #2
Source File: Streams.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks, whether the given file name is valid in the sense,
 * that it doesn't contain any NUL characters. If the file name
 * is valid, it will be returned without any modifications. Otherwise,
 * an {@link InvalidFileNameException} is raised.
 *
 * @param fileName The file name to check
 * @return Unmodified file name, if valid.
 * @throws InvalidFileNameException The file name was found to be invalid.
 */
public static String checkFileName(String fileName) {
    if (fileName != null  &&  fileName.indexOf('\u0000') != -1) {
        // pFileName.replace("\u0000", "\\0")
        final StringBuilder sb = new StringBuilder();
        for (int i = 0;  i < fileName.length();  i++) {
            char c = fileName.charAt(i);
            switch (c) {
                case 0:
                    sb.append("\\0");
                    break;
                default:
                    sb.append(c);
                    break;
            }
        }
        throw new InvalidFileNameException(fileName,
                "Invalid file name: " + sb);
    }
    return fileName;
}
 
Example #3
Source File: Streams.java    From AndroidWebServ with Apache License 2.0 6 votes vote down vote up
/**
 * Checks, whether the given file name is valid in the sense,
 * that it doesn't contain any NUL characters. If the file name
 * is valid, it will be returned without any modifications. Otherwise,
 * an {@link InvalidFileNameException} is raised.
 *
 * @param pFileName The file name to check
 * @return Unmodified file name, if valid.
 * @throws InvalidFileNameException The file name was found to be invalid.
 */
public static String checkFileName(String pFileName) {
    if (pFileName != null  &&  pFileName.indexOf('\u0000') != -1) {
        // pFileName.replace("\u0000", "\\0")
        final StringBuffer sb = new StringBuffer();
        for (int i = 0;  i < pFileName.length();  i++) {
            char c = pFileName.charAt(i);
            switch (c) {
                case 0:
                    sb.append("\\0");
                    break;
                default:
                    sb.append(c);
                    break;
            }
        }
        throw new InvalidFileNameException(pFileName,
                "Invalid file name: " + sb);
    }
    return pFileName;
}