001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.multipart; 018 019import org.springframework.lang.Nullable; 020 021/** 022 * MultipartException subclass thrown when an upload exceeds the 023 * maximum upload size allowed. 024 * 025 * @author Juergen Hoeller 026 * @since 1.0.1 027 */ 028@SuppressWarnings("serial") 029public class MaxUploadSizeExceededException extends MultipartException { 030 031 private final long maxUploadSize; 032 033 034 /** 035 * Constructor for MaxUploadSizeExceededException. 036 * @param maxUploadSize the maximum upload size allowed, 037 * or -1 if the size limit isn't known 038 */ 039 public MaxUploadSizeExceededException(long maxUploadSize) { 040 this(maxUploadSize, null); 041 } 042 043 /** 044 * Constructor for MaxUploadSizeExceededException. 045 * @param maxUploadSize the maximum upload size allowed, 046 * or -1 if the size limit isn't known 047 * @param ex root cause from multipart parsing API in use 048 */ 049 public MaxUploadSizeExceededException(long maxUploadSize, @Nullable Throwable ex) { 050 super("Maximum upload size " + (maxUploadSize >= 0 ? "of " + maxUploadSize + " bytes " : "") + "exceeded", ex); 051 this.maxUploadSize = maxUploadSize; 052 } 053 054 055 /** 056 * Return the maximum upload size allowed, 057 * or -1 if the size limit isn't known. 058 */ 059 public long getMaxUploadSize() { 060 return this.maxUploadSize; 061 } 062 063}