    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.fileupload;
    018
    019import java.io.File;
    020import java.util.List;
    021
    022import javax.servlet.http.HttpServletRequest;
    023
    024/**
    025 * <p>High level API for processing file uploads.</p>
    026 *
    027 * <p>This class handles multiple files per single HTML widget, sent using
    028 * {@code multipart/mixed} encoding type, as specified by
    029 * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>.  Use {@link
    030 * #parseRequest(HttpServletRequest)} to acquire a list of {@link
    031 * org.apache.commons.fileupload.FileItem}s associated with a given HTML
    032 * widget.</p>
    033 *
    034 * <p>Individual parts will be stored in temporary disk storage or in memory,
    035 * depending on their size, and will be available as {@link
    036 * org.apache.commons.fileupload.FileItem}s.</p>
    037 *
    038 * @deprecated 1.1 Use {@code ServletFileUpload} together with
    039 *             {@code DiskFileItemFactory} instead.
    040 */
    041@Deprecated
    042public class DiskFileUpload
    043    extends FileUploadBase {
    044
    045    /**
    046     * The factory to use to create new form items.
    047     */
    048    private DefaultFileItemFactory fileItemFactory;
    049
    050    /**
    051     * Constructs an instance of this class which uses the default factory to
    052     * create {@code FileItem} instances.
    053     *
    054     * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
    055     * @deprecated 1.1 Use {@code FileUpload} instead.
    056     */
    057    @Deprecated
    058    public DiskFileUpload() {
    059        this.fileItemFactory = new DefaultFileItemFactory();
    060    }
    061
    062    /**
    063     * Constructs an instance of this class which uses the supplied factory to
    064     * create {@code FileItem} instances.
    065     *
    066     * @see #DiskFileUpload()
    067     * @param fileItemFactory The file item factory to use.
    068     * @deprecated 1.1 Use {@code FileUpload} instead.
    069     */
    070    @Deprecated
    071    public DiskFileUpload(final DefaultFileItemFactory fileItemFactory) {
    072        this.fileItemFactory = fileItemFactory;
    073    }
    074
    075    /**
    076     * Returns the factory class used when creating file items.
    077     *
    078     * @return The factory class for new file items.
    079     * @deprecated 1.1 Use {@code FileUpload} instead.
    080     */
    081    @Override
    082    @Deprecated
    083    public FileItemFactory getFileItemFactory() {
    084        return fileItemFactory;
    085    }
    086
    087    /**
    088     * Returns the location used to temporarily store files that are larger
    089     * than the configured size threshold.
    090     *
    091     * @return The path to the temporary file location.
    092     * @see #setRepositoryPath(String)
    093     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
    094     */
    095    @Deprecated
    096    public String getRepositoryPath() {
    097        return fileItemFactory.getRepository().getPath();
    098    }
    099
    100    /**
    101     * Returns the size threshold beyond which files are written directly to
    102     * disk.
    103     *
    104     * @return The size threshold, in bytes.
    105     * @see #setSizeThreshold(int)
    106     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
    107     */
    108    @Deprecated
    109    public int getSizeThreshold() {
    110        return fileItemFactory.getSizeThreshold();
    111    }
    112
    113    /**
    114     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
    115     * compliant {@code multipart/form-data} stream. If files are stored
    116     * on disk, the path is given by {@code getRepository()}.
    117     *
    118     * @param req           The servlet request to be parsed. Must be non-null.
    119     * @param sizeThreshold The max size in bytes to be stored in memory.
    120     * @param sizeMax       The maximum allowed upload size, in bytes.
    121     * @param path          The location where the files should be stored.
    122     * @return A list of {@code FileItem} instances parsed from the
    123     *         request, in the order that they were transmitted.
    124     *
    125     * @throws FileUploadException if there are problems reading/parsing
    126     *                             the request or storing files.
    127     *
    128     * @deprecated 1.1 Use {@code ServletFileUpload} instead.
    129     */
    130    @Deprecated
    131    public List<FileItem> parseRequest(final HttpServletRequest req,
    132                                            final int sizeThreshold,
    133                                            final long sizeMax, final String path)
    134        throws FileUploadException {
    135        setSizeThreshold(sizeThreshold);
    136        setSizeMax(sizeMax);
    137        setRepositoryPath(path);
    138        return parseRequest(req);
    139    }
    140
    141    /**
    142     * Sets the factory class to use when creating file items. The factory must
    143     * be an instance of {@code DefaultFileItemFactory} or a subclass
    144     * thereof, or else a {@code ClassCastException} will be thrown.
    145     *
    146     * @param fileItemFactory The factory class for new file items.
    147     * @deprecated 1.1 Use {@code FileUpload} instead.
    148     */
    149    @Override
    150    @Deprecated
    151    public void setFileItemFactory(final FileItemFactory fileItemFactory) {
    152        this.fileItemFactory = (DefaultFileItemFactory) fileItemFactory;
    153    }
    154
    155    /**
    156     * Sets the location used to temporarily store files that are larger
    157     * than the configured size threshold.
    158     *
    159     * @param repositoryPath The path to the temporary file location.
    160     * @see #getRepositoryPath()
    161     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
    162     */
    163    @Deprecated
    164    public void setRepositoryPath(final String repositoryPath) {
    165        fileItemFactory.setRepository(new File(repositoryPath));
    166    }
    167
    168    /**
    169     * Sets the size threshold beyond which files are written directly to disk.
    170     *
    171     * @param sizeThreshold The size threshold, in bytes.
    172     * @see #getSizeThreshold()
    173     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
    174     */
    175    @Deprecated
    176    public void setSizeThreshold(final int sizeThreshold) {
    177        fileItemFactory.setSizeThreshold(sizeThreshold);
    178    }
    179
    180}