    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     */
    017    package org.apache.commons.fileupload;
    018
    019    import java.io.IOException;
    020    import java.io.InputStream;
    021
    022
    023    /**
    024     * <p> This interface provides access to a file or form item that was
    025     * received within a <code>multipart/form-data</code> POST request.
    026     * The items contents are retrieved by calling {@link #openStream()}.</p>
    027     * <p>Instances of this class are created by accessing the
    028     * iterator, returned by
    029     * {@link FileUploadBase#getItemIterator(RequestContext)}.</p>
    030     * <p><em>Note</em>: There is an interaction between the iterator and
    031     * its associated instances of {@link FileItemStream}: By invoking
    032     * {@link java.util.Iterator#hasNext()} on the iterator, you discard all data,
    033     * which hasn't been read so far from the previous data.</p>
    034     */
    035    public interface FileItemStream extends FileItemHeadersSupport {
    036        /**
    037         * This exception is thrown, if an attempt is made to read
    038         * data from the {@link InputStream}, which has been returned
    039         * by {@link FileItemStream#openStream()}, after
    040         * {@link java.util.Iterator#hasNext()} has been invoked on the
    041         * iterator, which created the {@link FileItemStream}.
    042         */
    043        public static class ItemSkippedException extends IOException {
    044            /**
    045             * The exceptions serial version UID, which is being used
    046             * when serializing an exception instance.
    047             */
    048            private static final long serialVersionUID = -7280778431581963740L;
    049        }
    050
    051        /** Creates an {@link InputStream}, which allows to read the
    052         * items contents.
    053         * @return The input stream, from which the items data may
    054         *   be read.
    055         * @throws IllegalStateException The method was already invoked on
    056         * this item. It is not possible to recreate the data stream.
    057         * @throws IOException An I/O error occurred.
    058         * @see ItemSkippedException
    059         */
    060        InputStream openStream() throws IOException;
    061
    062        /**
    063         * Returns the content type passed by the browser or <code>null</code> if
    064         * not defined.
    065         *
    066         * @return The content type passed by the browser or <code>null</code> if
    067         *         not defined.
    068         */
    069        String getContentType();
    070
    071        /**
    072         * Returns the original filename in the client's filesystem, as provided by
    073         * the browser (or other client software). In most cases, this will be the
    074         * base file name, without path information. However, some clients, such as
    075         * the Opera browser, do include path information.
    076         *
    077         * @return The original filename in the client's filesystem.
    078         */
    079        String getName();
    080
    081        /**
    082         * Returns the name of the field in the multipart form corresponding to
    083         * this file item.
    084         *
    085         * @return The name of the form field.
    086         */
    087        String getFieldName();
    088
    089        /**
    090         * Determines whether or not a <code>FileItem</code> instance represents
    091         * a simple form field.
    092         *
    093         * @return <code>true</code> if the instance represents a simple form
    094         *         field; <code>false</code> if it represents an uploaded file.
    095         */
    096        boolean isFormField();
    097    }