Coverage Report - org.apache.commons.fileupload.DiskFileUpload
 
Classes in this File Line Coverage Branch Coverage Complexity
DiskFileUpload
15%
3/19
N/A
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.fileupload;
 18  
 
 19  
 import java.io.File;
 20  
 import java.util.List;
 21  
 import javax.servlet.http.HttpServletRequest;
 22  
 
 23  
 /**
 24  
  * <p>High level API for processing file uploads.</p>
 25  
  *
 26  
  * <p>This class handles multiple files per single HTML widget, sent using
 27  
  * <code>multipart/mixed</code> encoding type, as specified by
 28  
  * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>.  Use {@link
 29  
  * #parseRequest(HttpServletRequest)} to acquire a list of {@link
 30  
  * org.apache.commons.fileupload.FileItem}s associated with a given HTML
 31  
  * widget.</p>
 32  
  *
 33  
  * <p>Individual parts will be stored in temporary disk storage or in memory,
 34  
  * depending on their size, and will be available as {@link
 35  
  * org.apache.commons.fileupload.FileItem}s.</p>
 36  
  *
 37  
  * @deprecated 1.1 Use <code>ServletFileUpload</code> together with
 38  
  *             <code>DiskFileItemFactory</code> instead.
 39  
  */
 40  
 @Deprecated
 41  
 public class DiskFileUpload
 42  
     extends FileUploadBase {
 43  
 
 44  
     // ----------------------------------------------------------- Data members
 45  
 
 46  
     /**
 47  
      * The factory to use to create new form items.
 48  
      */
 49  
     private DefaultFileItemFactory fileItemFactory;
 50  
 
 51  
     // ----------------------------------------------------------- Constructors
 52  
 
 53  
     /**
 54  
      * Constructs an instance of this class which uses the default factory to
 55  
      * create <code>FileItem</code> instances.
 56  
      *
 57  
      * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
 58  
      *
 59  
      * @deprecated 1.1 Use <code>FileUpload</code> instead.
 60  
      */
 61  
     @Deprecated
 62  
     public DiskFileUpload() {
 63  2
         super();
 64  2
         this.fileItemFactory = new DefaultFileItemFactory();
 65  2
     }
 66  
 
 67  
     /**
 68  
      * Constructs an instance of this class which uses the supplied factory to
 69  
      * create <code>FileItem</code> instances.
 70  
      *
 71  
      * @see #DiskFileUpload()
 72  
      * @param fileItemFactory The file item factory to use.
 73  
      *
 74  
      * @deprecated 1.1 Use <code>FileUpload</code> instead.
 75  
      */
 76  
     @Deprecated
 77  
     public DiskFileUpload(DefaultFileItemFactory fileItemFactory) {
 78  0
         super();
 79  0
         this.fileItemFactory = fileItemFactory;
 80  0
     }
 81  
 
 82  
     // ----------------------------------------------------- Property accessors
 83  
 
 84  
     /**
 85  
      * Returns the factory class used when creating file items.
 86  
      *
 87  
      * @return The factory class for new file items.
 88  
      *
 89  
      * @deprecated 1.1 Use <code>FileUpload</code> instead.
 90  
      */
 91  
     @Override
 92  
     @Deprecated
 93  
     public FileItemFactory getFileItemFactory() {
 94  0
         return fileItemFactory;
 95  
     }
 96  
 
 97  
     /**
 98  
      * Sets the factory class to use when creating file items. The factory must
 99  
      * be an instance of <code>DefaultFileItemFactory</code> or a subclass
 100  
      * thereof, or else a <code>ClassCastException</code> will be thrown.
 101  
      *
 102  
      * @param factory The factory class for new file items.
 103  
      *
 104  
      * @deprecated 1.1 Use <code>FileUpload</code> instead.
 105  
      */
 106  
     @Override
 107  
     @Deprecated
 108  
     public void setFileItemFactory(FileItemFactory factory) {
 109  0
         this.fileItemFactory = (DefaultFileItemFactory) factory;
 110  0
     }
 111  
 
 112  
     /**
 113  
      * Returns the size threshold beyond which files are written directly to
 114  
      * disk.
 115  
      *
 116  
      * @return The size threshold, in bytes.
 117  
      *
 118  
      * @see #setSizeThreshold(int)
 119  
      *
 120  
      * @deprecated 1.1 Use <code>DiskFileItemFactory</code> instead.
 121  
      */
 122  
     @Deprecated
 123  
     public int getSizeThreshold() {
 124  0
         return fileItemFactory.getSizeThreshold();
 125  
     }
 126  
 
 127  
     /**
 128  
      * Sets the size threshold beyond which files are written directly to disk.
 129  
      *
 130  
      * @param sizeThreshold The size threshold, in bytes.
 131  
      *
 132  
      * @see #getSizeThreshold()
 133  
      *
 134  
      * @deprecated 1.1 Use <code>DiskFileItemFactory</code> instead.
 135  
      */
 136  
     @Deprecated
 137  
     public void setSizeThreshold(int sizeThreshold) {
 138  0
         fileItemFactory.setSizeThreshold(sizeThreshold);
 139  0
     }
 140  
 
 141  
     /**
 142  
      * Returns the location used to temporarily store files that are larger
 143  
      * than the configured size threshold.
 144  
      *
 145  
      * @return The path to the temporary file location.
 146  
      *
 147  
      * @see #setRepositoryPath(String)
 148  
      *
 149  
      * @deprecated 1.1 Use <code>DiskFileItemFactory</code> instead.
 150  
      */
 151  
     @Deprecated
 152  
     public String getRepositoryPath() {
 153  0
         return fileItemFactory.getRepository().getPath();
 154  
     }
 155  
 
 156  
     /**
 157  
      * Sets the location used to temporarily store files that are larger
 158  
      * than the configured size threshold.
 159  
      *
 160  
      * @param repositoryPath The path to the temporary file location.
 161  
      *
 162  
      * @see #getRepositoryPath()
 163  
      *
 164  
      * @deprecated 1.1 Use <code>DiskFileItemFactory</code> instead.
 165  
      */
 166  
     @Deprecated
 167  
     public void setRepositoryPath(String repositoryPath) {
 168  0
         fileItemFactory.setRepository(new File(repositoryPath));
 169  0
     }
 170  
 
 171  
     // --------------------------------------------------------- Public methods
 172  
 
 173  
     /**
 174  
      * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
 175  
      * compliant <code>multipart/form-data</code> stream. If files are stored
 176  
      * on disk, the path is given by <code>getRepository()</code>.
 177  
      *
 178  
      * @param req           The servlet request to be parsed. Must be non-null.
 179  
      * @param sizeThreshold The max size in bytes to be stored in memory.
 180  
      * @param sizeMax       The maximum allowed upload size, in bytes.
 181  
      * @param path          The location where the files should be stored.
 182  
      *
 183  
      * @return A list of <code>FileItem</code> instances parsed from the
 184  
      *         request, in the order that they were transmitted.
 185  
      *
 186  
      * @throws FileUploadException if there are problems reading/parsing
 187  
      *                             the request or storing files.
 188  
      *
 189  
      * @deprecated 1.1 Use <code>ServletFileUpload</code> instead.
 190  
      */
 191  
     @Deprecated
 192  
     public List<FileItem> parseRequest(HttpServletRequest req,
 193  
                                             int sizeThreshold,
 194  
                                             long sizeMax, String path)
 195  
         throws FileUploadException {
 196  0
         setSizeThreshold(sizeThreshold);
 197  0
         setSizeMax(sizeMax);
 198  0
         setRepositoryPath(path);
 199  0
         return parseRequest(req);
 200  
     }
 201  
 
 202  
 }