View Javadoc

    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.IOException;
    20  import java.io.InputStream;
    21
    22
    23  /**
    24   * <p> This interface provides access to a file or form item that was
    25   * received within a <code>multipart/form-data</code> POST request.
    26   * The items contents are retrieved by calling {@link #openStream()}.</p>
    27   * <p>Instances of this class are created by accessing the
    28   * iterator, returned by
    29   * {@link FileUploadBase#getItemIterator(RequestContext)}.</p>
    30   * <p><em>Note</em>: There is an interaction between the iterator and
    31   * its associated instances of {@link FileItemStream}: By invoking
    32   * {@link java.util.Iterator#hasNext()} on the iterator, you discard all data,
    33   * which hasn't been read so far from the previous data.</p>
    34   */
    35  public interface FileItemStream extends FileItemHeadersSupport {
    36      /**
    37       * This exception is thrown, if an attempt is made to read
    38       * data from the {@link InputStream}, which has been returned
    39       * by {@link FileItemStream#openStream()}, after
    40       * {@link java.util.Iterator#hasNext()} has been invoked on the
    41       * iterator, which created the {@link FileItemStream}.
    42       */
    43      public static class ItemSkippedException extends IOException {
    44          /**
    45           * The exceptions serial version UID, which is being used
    46           * when serializing an exception instance.
    47           */
    48          private static final long serialVersionUID = -7280778431581963740L;
    49      }
    50
    51      /** Creates an {@link InputStream}, which allows to read the
    52       * items contents.
    53       * @return The input stream, from which the items data may
    54       *   be read.
    55       * @throws IllegalStateException The method was already invoked on
    56       * this item. It is not possible to recreate the data stream.
    57       * @throws IOException An I/O error occurred.
    58       * @see ItemSkippedException
    59       */
    60      InputStream openStream() throws IOException;
    61
    62      /**
    63       * Returns the content type passed by the browser or <code>null</code> if
    64       * not defined.
    65       *
    66       * @return The content type passed by the browser or <code>null</code> if
    67       *         not defined.
    68       */
    69      String getContentType();
    70
    71      /**
    72       * Returns the original filename in the client's filesystem, as provided by
    73       * the browser (or other client software). In most cases, this will be the
    74       * base file name, without path information. However, some clients, such as
    75       * the Opera browser, do include path information.
    76       *
    77       * @return The original filename in the client's filesystem.
    78       */
    79      String getName();
    80
    81      /**
    82       * Returns the name of the field in the multipart form corresponding to
    83       * this file item.
    84       *
    85       * @return The name of the form field.
    86       */
    87      String getFieldName();
    88
    89      /**
    90       * Determines whether or not a <code>FileItem</code> instance represents
    91       * a simple form field.
    92       *
    93       * @return <code>true</code> if the instance represents a simple form
    94       *         field; <code>false</code> if it represents an uploaded file.
    95       */
    96      boolean isFormField();
    97  }