Skip to content

Commit 5135b22

Browse files
Use FileItem.write() to write
1 parent a44799d commit 5135b22

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/com/conveyal/analysis/util/HttpUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.conveyal.file.FileUtils;
55
import com.conveyal.r5.util.ExceptionUtils;
66
import org.apache.commons.fileupload.FileItem;
7-
import org.apache.commons.fileupload.disk.DiskFileItem;
87
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
98
import org.apache.commons.fileupload.servlet.ServletFileUpload;
109

@@ -109,13 +108,15 @@ public static File saveFileItemLocally(FileItem fileItem) {
109108
}
110109

111110
/**
112-
* Move the contents of a `FileItem` to the given directory by calling `renameTo`.
111+
* Move the contents of a `FileItem` to the given directory by calling `write`. `DiskFileItem`s will call `renameTo`
112+
* if the `FileItem's contents are already on the disk.
113113
*/
114114
public static File moveFileItemIntoDirectory(FileItem fileItem, File directory) {
115115
File file = new File(directory, fileItem.getName());
116-
boolean renameSuccessful = ((DiskFileItem) fileItem).getStoreLocation().renameTo(file);
117-
if (!renameSuccessful) {
118-
throw AnalysisServerException.fileUpload("Error storing file in directory on disk. File.renameTo() failed.");
116+
try {
117+
fileItem.write(file);
118+
} catch (Exception e) {
119+
throw new AnalysisServerException(e, "Error storing file in directory on disk. FileItem.write() failed.");
119120
}
120121
return file;
121122
}

0 commit comments

Comments
 (0)