-
Notifications
You must be signed in to change notification settings - Fork 78
/
MultipartConfigElement.java
117 lines (106 loc) · 3.79 KB
/
MultipartConfigElement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (c) 2017, 2022 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.servlet;
import jakarta.servlet.annotation.MultipartConfig;
/**
* Java Class representation of an {@link MultipartConfig} annotation value.
*
* @since Servlet 3.0
*/
public class MultipartConfigElement {
private final String location;
private final long maxFileSize;
private final long maxRequestSize;
private final int fileSizeThreshold;
/**
* Constructs an instance with defaults for all but location.
*
* @param location defaults to "" if values is null.
*/
public MultipartConfigElement(String location) {
if (location == null) {
this.location = "";
} else {
this.location = location;
}
this.maxFileSize = -1L;
this.maxRequestSize = -1L;
this.fileSizeThreshold = 0;
}
/**
* Constructs an instance with all values specified.
*
* @param location the directory location where files will be stored
* @param maxFileSize the maximum size allowed (in bytes) for uploaded files
* @param maxRequestSize the maximum size allowed (in bytes) for multipart/form-data requests
* @param fileSizeThreshold the size threshold (in bytes) after which files will be written to disk
*/
public MultipartConfigElement(String location, long maxFileSize, long maxRequestSize, int fileSizeThreshold) {
if (location == null) {
this.location = "";
} else {
this.location = location;
}
this.maxFileSize = maxFileSize;
this.maxRequestSize = maxRequestSize;
this.fileSizeThreshold = fileSizeThreshold;
}
/**
* Constructs an instance from a {@link MultipartConfig} annotation value.
*
* @param annotation the annotation value
*/
public MultipartConfigElement(MultipartConfig annotation) {
this.location = annotation.location();
this.fileSizeThreshold = annotation.fileSizeThreshold();
this.maxFileSize = annotation.maxFileSize();
this.maxRequestSize = annotation.maxRequestSize();
}
/**
* Gets the directory location where files will be stored.
*
* @return the directory location where files will be stored
*/
public String getLocation() {
return this.location;
}
/**
* Gets the maximum size allowed (in bytes) for uploaded files.
*
* @return the maximum size allowed (in bytes) for uploaded files
*/
public long getMaxFileSize() {
return this.maxFileSize;
}
/**
* Gets the maximum size allowed (in bytes) for multipart/form-data requests.
*
* @return the maximum size allowed (in bytes) for multipart/form-data requests
*/
public long getMaxRequestSize() {
return this.maxRequestSize;
}
/**
* Gets the size threshold (in bytes) after which files will be written to disk. A value of zero means files must always
* be written to disk.
*
* @return the size threshold (in bytes) after which files will be written to disk
*/
public int getFileSizeThreshold() {
return this.fileSizeThreshold;
}
}