001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.fileupload2.core;
018
019/**
020 * Signals that a file size exceeds the configured maximum.
021 */
022public class FileUploadByteCountLimitException extends FileUploadSizeException {
023
024    /**
025     * The exceptions UID, for serializing an instance.
026     */
027    private static final long serialVersionUID = 2;
028
029    /**
030     * File name of the item, which caused the exception.
031     */
032    private final String fileName;
033
034    /**
035     * Field name of the item, which caused the exception.
036     */
037    private final String fieldName;
038
039    /**
040     * Constructs an instance with the specified detail message, and actual and permitted sizes.
041     *
042     * @param message   The detail message (which is saved for later retrieval by the {@link #getMessage()} method)
043     * @param actual    The actual request size.
044     * @param permitted The maximum permitted request size.
045     * @param fileName  File name of the item, which caused the exception.
046     * @param fieldName Field name of the item, which caused the exception.
047     */
048    public FileUploadByteCountLimitException(final String message, final long actual, final long permitted, final String fileName, final String fieldName) {
049        super(message, permitted, actual);
050        this.fileName = fileName;
051        this.fieldName = fieldName;
052    }
053
054    /**
055     * Gets the field name of the item, which caused the exception.
056     *
057     * @return Field name, if known, or null.
058     */
059    public String getFieldName() {
060        return fieldName;
061    }
062
063    /**
064     * Gets the file name of the item, which caused the exception.
065     *
066     * @return File name, if known, or null.
067     */
068    public String getFileName() {
069        return fileName;
070    }
071
072}