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