Repository: wicket Updated Branches: refs/heads/wicket-6.x 176e2b4f6 -> 28ac20584
WICKET-5659 Add a setting to MultiFileUploadField to not close the file uploads' streams (cherry picked from commit 38d6b4a9c1bcf2a6ebcddeefcdf372839ca80e5c) Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/28ac2058 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/28ac2058 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/28ac2058 Branch: refs/heads/wicket-6.x Commit: 28ac20584d868f92b3b937743ae76ca3a216cdbe Parents: 176e2b4 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Mon Aug 4 11:40:11 2014 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Mon Aug 4 11:40:38 2014 +0200 ---------------------------------------------------------------------- .../html/form/upload/MultiFileUploadField.java | 41 +++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/28ac2058/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java index 4e803a3..179151f 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java @@ -329,30 +329,45 @@ public class MultiFileUploadField extends FormComponentPanel<Collection<FileUplo @Override protected void onDetach() { - // cleanup any opened filestreams - Collection<FileUpload> uploads = getConvertedInput(); - if (uploads != null) + if (forceCloseStreamsOnDetach()) { - for (FileUpload upload : uploads) + // cleanup any opened filestreams + Collection<FileUpload> uploads = getConvertedInput(); + if (uploads != null) { - upload.closeStreams(); + for (FileUpload upload : uploads) + { + upload.closeStreams(); + } } - } - // cleanup any caches - inputArrayCache = null; + // cleanup any caches + inputArrayCache = null; - // clean up the model because we don't want FileUpload objects in session - Collection<FileUpload> modelObject = getModelObject(); - if (modelObject != null) - { - modelObject.clear(); + // clean up the model because we don't want FileUpload objects in session + Collection<FileUpload> modelObject = getModelObject(); + if (modelObject != null) + { + modelObject.clear(); + } } super.onDetach(); } /** + * The FileUploadField will close any input streams you have opened in its FileUpload by + * default. If you wish to manage the stream yourself (e.g. you want to use it in another + * thread) then you can override this method to prevent this behavior. + * + * @return <code>true</code> if stream should be closed at the end of request + */ + protected boolean forceCloseStreamsOnDetach() + { + return true; + } + + /** * Model that will construct the caption string * * @author ivaynberg
