WICKET-5659 Add a setting to MultiFileUploadField to not close the file uploads' streams
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/38d6b4a9 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/38d6b4a9 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/38d6b4a9 Branch: refs/heads/master Commit: 38d6b4a9c1bcf2a6ebcddeefcdf372839ca80e5c Parents: 34b46ca 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:11 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/38d6b4a9/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 42191ba..e6d4c2b 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
