Skip to content

Commit

Permalink
Extract constant strings
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jun 11, 2023
1 parent 93ea7c1 commit 9de9d63
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@
*/
public abstract class AbstractFileUpload {

/**
* Boundary parameter key.
*/
private static final String BOUNDARY_KEY = "boundary";

/**
* Name parameter key.
*/
private static final String NAME_KEY = "name";

/**
* File name parameter key.
*/
private static final String FILENAME_KEY = "filename";

/**
* HTTP content type header name.
*/
Expand Down Expand Up @@ -137,7 +152,7 @@ public byte[] getBoundary(final String contentType) {
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
final Map<String, String> params = parser.parse(contentType, new char[] { ';', ',' });
final String boundaryStr = params.get("boundary");
final String boundaryStr = params.get(BOUNDARY_KEY);

if (boundaryStr == null) {
return null;
Expand Down Expand Up @@ -170,7 +185,7 @@ private String getFieldName(final String contentDisposition) {
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
final Map<String, String> params = parser.parse(contentDisposition, ';');
fieldName = params.get("name");
fieldName = params.get(NAME_KEY);
if (fieldName != null) {
fieldName = fieldName.trim();
}
Expand Down Expand Up @@ -220,8 +235,8 @@ private String getFileName(final String contentDisposition) {
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
final Map<String, String> params = parser.parse(contentDisposition, ';');
if (params.containsKey("filename")) {
fileName = params.get("filename");
if (params.containsKey(FILENAME_KEY)) {
fileName = params.get(FILENAME_KEY);
if (fileName != null) {
fileName = fileName.trim();
} else {
Expand Down Expand Up @@ -392,7 +407,6 @@ public Map<String, List<FileItem>> parseParameterMap(final RequestContext ctx) t
for (final FileItem fileItem : items) {
final String fieldName = fileItem.getFieldName();
final List<FileItem> mappedItems = itemsMap.computeIfAbsent(fieldName, k -> new ArrayList<>());

mappedItems.add(fileItem);
}

Expand Down

0 comments on commit 9de9d63

Please sign in to comment.