Skip to content

Commit

Permalink
Update comments and consolidate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed Oct 27, 2023
1 parent 050af77 commit e81b869
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/main/java/com/conveyal/analysis/util/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public static Map<String, List<FileItem>> getRequestFiles (HttpServletRequest re
// The Javadoc on this factory class doesn't say anything about thread safety. Looking at the source code it
// all looks threadsafe. But also very lightweight to instantiate, so in this code run by multiple threads
// we play it safe and always create a new factory.
// Setting a size threshold of 0 causes all files to be written to disk, which allows processing them in a
// uniform way in other threads, after the request handler has returned. This does however cause some very
// small form fields to be written to disk files. Ideally we'd identify the smallest actual file we'll ever
// handle and set the threshold a little higher. The downside is that if a tiny file is actually uploaded even
// by accident, our code will not be able to get a file handle for it and fail. Some legitimate files like
// Shapefile .prj sidecars can be really small.
// If we always saved the FileItems via write() or read them with getInputStream() they would not all need to
// be on disk.
try {
ServletFileUpload sfu = new ServletFileUpload();
return sfu.parseParameterMap(req);
Expand Down Expand Up @@ -69,15 +61,12 @@ public static String getFormField(Map<String, List<FileItem>> formFields, String
}
}

public static List<File> storeFileItemsAndUnzip(List<FileItem> fileItems) {
return storeFileItemsAndUnzip(fileItems, FileUtils.createScratchDirectory());
}

/**
* Convert `FileItem`s into `File`s and move them into the given directory. Automatically unzip files. Return the
* list of new `File` handles.
* Convert `FileItem`s into `File`s and move them into a temp directory. Automatically unzip files. Return the list
* of new `File` handles.
*/
public static List<File> storeFileItemsAndUnzip(List<FileItem> fileItems, File directory) {
public static List<File> storeFileItemsAndUnzip(List<FileItem> fileItems) {
File directory = FileUtils.createScratchDirectory();
List<File> files = new ArrayList<>();
for (FileItem fi : fileItems) {
File file = storeFileItemInDirectory(fi, directory);
Expand All @@ -91,6 +80,9 @@ public static List<File> storeFileItemsAndUnzip(List<FileItem> fileItems, File d
return files;
}

/**
* Convert `FileItem`s into `File`s and move them into a temporary directory. Return the list of new `File` handles.
*/
public static List<File> storeFileItems(List<FileItem> fileItems) {
File directory = FileUtils.createScratchDirectory();
List<File> files = new ArrayList<>();
Expand Down

0 comments on commit e81b869

Please sign in to comment.