Java Code Examples for org.apache.tomcat.util.http.fileupload.InvalidFileNameException

The following examples show how to use org.apache.tomcat.util.http.fileupload.InvalidFileNameException. These examples are extracted from open source projects. 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 Project: Tomcat8-Source-Read   Source File: Streams.java    License: 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 Project: Tomcat7.0.67   Source File: Streams.java    License: 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 StringBuilder sb = new StringBuilder();
        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;
}
 
Example 3
Source Project: tomcatsrc   Source File: Streams.java    License: 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 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;
}