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 * 034 * @version $Id: FileItemStream.java 1454691 2013-03-09 12:15:54Z simonetripodi $ 035 */ 036public interface FileItemStream extends FileItemHeadersSupport { 037 038 /** 039 * This exception is thrown, if an attempt is made to read 040 * data from the {@link InputStream}, which has been returned 041 * by {@link FileItemStream#openStream()}, after 042 * {@link java.util.Iterator#hasNext()} has been invoked on the 043 * iterator, which created the {@link FileItemStream}. 044 */ 045 public static class ItemSkippedException extends IOException { 046 047 /** 048 * The exceptions serial version UID, which is being used 049 * when serializing an exception instance. 050 */ 051 private static final long serialVersionUID = -7280778431581963740L; 052 053 } 054 055 /** 056 * Creates an {@link InputStream}, which allows to read the 057 * items contents. 058 * 059 * @return The input stream, from which the items data may 060 * be read. 061 * @throws IllegalStateException The method was already invoked on 062 * this item. It is not possible to recreate the data stream. 063 * @throws IOException An I/O error occurred. 064 * @see ItemSkippedException 065 */ 066 InputStream openStream() throws IOException; 067 068 /** 069 * Returns the content type passed by the browser or <code>null</code> if 070 * not defined. 071 * 072 * @return The content type passed by the browser or <code>null</code> if 073 * not defined. 074 */ 075 String getContentType(); 076 077 /** 078 * Returns the original filename in the client's filesystem, as provided by 079 * the browser (or other client software). In most cases, this will be the 080 * base file name, without path information. However, some clients, such as 081 * the Opera browser, do include path information. 082 * 083 * @return The original filename in the client's filesystem. 084 */ 085 String getName(); 086 087 /** 088 * Returns the name of the field in the multipart form corresponding to 089 * this file item. 090 * 091 * @return The name of the form field. 092 */ 093 String getFieldName(); 094 095 /** 096 * Determines whether or not a <code>FileItem</code> instance represents 097 * a simple form field. 098 * 099 * @return <code>true</code> if the instance represents a simple form 100 * field; <code>false</code> if it represents an uploaded file. 101 */ 102 boolean isFormField(); 103 104}