@@ -437,17 +437,6 @@ public File getStoreLocation() {
437
437
}
438
438
// ------------------------------------------------------ Protected methods
439
439
440
- /**
441
- * Removes the file contents from the temporary storage.
442
- */
443
- protected void finalize () {
444
- File outputFile = dfos .getFile ();
445
-
446
- if (outputFile != null && outputFile .exists ()) {
447
- outputFile .delete ();
448
- }
449
- }
450
-
451
440
/**
452
441
* Creates and returns a {@link java.io.File File} representing a uniquely
453
442
* named temporary file in the configured repository path. The lifetime of
@@ -525,37 +514,42 @@ public Map<String, String[]> parse(InputStream body) {
525
514
FileItemStream item = iter .next ();
526
515
FileItem fileItem = new AutoFileItem (item );
527
516
try {
528
- Streams .copy (item .openStream (), fileItem .getOutputStream (), true );
529
- } catch (FileUploadIOException e ) {
530
- throw (FileUploadException ) e .getCause ();
531
- } catch (IOException e ) {
532
- throw new IOFileUploadException ("Processing of " + MULTIPART_FORM_DATA + " request failed. " + e .getMessage (), e );
533
- }
534
- if (fileItem .isFormField ()) {
535
- // must resolve encoding
536
- String _encoding = Request .current ().encoding ; // this is our default
537
- String _contentType = fileItem .getContentType ();
538
- if ( _contentType != null ) {
539
- HTTP .ContentTypeWithEncoding contentTypeEncoding = HTTP .parseContentType (_contentType );
540
- if ( contentTypeEncoding .encoding != null ) {
541
- _encoding = contentTypeEncoding .encoding ;
542
- }
517
+ try {
518
+ Streams .copy (item .openStream (), fileItem .getOutputStream (), true );
519
+ } catch (FileUploadIOException e ) {
520
+ throw (FileUploadException ) e .getCause ();
521
+ } catch (IOException e ) {
522
+ throw new IOFileUploadException ("Processing of " + MULTIPART_FORM_DATA + " request failed. " + e .getMessage (), e );
543
523
}
524
+ if (fileItem .isFormField ()) {
525
+ // must resolve encoding
526
+ String _encoding = Request .current ().encoding ; // this is our default
527
+ String _contentType = fileItem .getContentType ();
528
+ if ( _contentType != null ) {
529
+ HTTP .ContentTypeWithEncoding contentTypeEncoding = HTTP .parseContentType (_contentType );
530
+ if ( contentTypeEncoding .encoding != null ) {
531
+ _encoding = contentTypeEncoding .encoding ;
532
+ }
533
+ }
544
534
545
- putMapEntry (result , fileItem .getFieldName (), fileItem .getString ( _encoding ));
546
- } else {
547
- @ SuppressWarnings ("unchecked" ) List <Upload > uploads = (List <Upload >) Request .current ().args .get ("__UPLOADS" );
548
- if (uploads == null ) {
549
- uploads = new ArrayList <Upload >();
550
- Request .current ().args .put ("__UPLOADS" , uploads );
551
- }
552
- try {
553
- uploads .add (new FileUpload (fileItem ));
554
- } catch (Exception e ) {
555
- // GAE does not support it, we try in memory
556
- uploads .add (new MemoryUpload (fileItem ));
535
+ putMapEntry (result , fileItem .getFieldName (), fileItem .getString ( _encoding ));
536
+ } else {
537
+ @ SuppressWarnings ("unchecked" ) List <Upload > uploads = (List <Upload >) Request .current ().args .get ("__UPLOADS" );
538
+ if (uploads == null ) {
539
+ uploads = new ArrayList <Upload >();
540
+ Request .current ().args .put ("__UPLOADS" , uploads );
541
+ }
542
+ try {
543
+ uploads .add (new FileUpload (fileItem ));
544
+ } catch (Exception e ) {
545
+ // GAE does not support it, we try in memory
546
+ uploads .add (new MemoryUpload (fileItem ));
547
+ }
548
+ putMapEntry (result , fileItem .getFieldName (), fileItem .getFieldName ());
557
549
}
558
- putMapEntry (result , fileItem .getFieldName (), fileItem .getFieldName ());
550
+ }
551
+ finally {
552
+ fileItem .delete ();
559
553
}
560
554
}
561
555
} catch (FileUploadIOException e ) {
0 commit comments