From e768117fc259f4f482424f6e99a858f6e7bf7df5 Mon Sep 17 00:00:00 2001 From: Trevor Gerhardt Date: Fri, 27 Oct 2023 19:28:55 +0800 Subject: [PATCH] Update comments and consolidate methods --- .../com/conveyal/analysis/util/HttpUtils.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/conveyal/analysis/util/HttpUtils.java b/src/main/java/com/conveyal/analysis/util/HttpUtils.java index b84f77ff3..55f8e1047 100644 --- a/src/main/java/com/conveyal/analysis/util/HttpUtils.java +++ b/src/main/java/com/conveyal/analysis/util/HttpUtils.java @@ -30,14 +30,6 @@ public static Map> 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); @@ -69,15 +61,12 @@ public static String getFormField(Map> formFields, String } } - public static List storeFileItemsAndUnzip(List 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 storeFileItemsAndUnzip(List fileItems, File directory) { + public static List storeFileItemsAndUnzip(List fileItems) { + File directory = FileUtils.createScratchDirectory(); List files = new ArrayList<>(); for (FileItem fi : fileItems) { File file = storeFileItemInDirectory(fi, directory); @@ -91,6 +80,9 @@ public static List storeFileItemsAndUnzip(List 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 storeFileItems(List fileItems) { File directory = FileUtils.createScratchDirectory(); List files = new ArrayList<>();