org.apache.turbine.util.upload
Class FileItem

java.lang.Object
  extended byorg.apache.turbine.util.upload.FileItem
All Implemented Interfaces:
javax.activation.DataSource

Deprecated. use commons-fileupload instead

public class FileItem
extends java.lang.Object
implements javax.activation.DataSource

This class represents a file that was received by Turbine using multipart/form-data POST request.

After retrieving an instance of this class from the ParameterParser (see ParameterParser.getFileItem(String) and ParameterParser.getFileItems(String)) you can use it to acces the data that was sent by the browser. You may either request all contents of file at once using get() or request an InputStream with getStream() and process the file without attempting to load it into memory, which may come handy with large files. Implements the javax.activation.DataSource interface (which allows for example the adding of a FileItem as an attachment to a multipart email).

Version:
$Id: FileItem.java 264148 2005-08-29 14:21:04Z henning $
Author:
Rafal Krzewski, Sean Legassick, Jason van Zyl

Field Summary
protected  java.io.ByteArrayOutputStream byteStream
          Deprecated. Temporary storage for in-memory files.
protected  byte[] content
          Deprecated. Cached contents of the file.
protected  java.lang.String contentType
          Deprecated. The content type passed by the browser or null if not defined.
static int DEFAULT_UPLOAD_SIZE_THRESHOLD
          Deprecated. The maximal size of request that will have it's elements stored in memory.
protected  java.lang.String fileName
          Deprecated. The original filename in the user's filesystem.
protected  java.io.File storeLocation
          Deprecated. Temporary storage location.
 
Constructor Summary
protected FileItem(java.lang.String fileName, java.lang.String contentType)
          Deprecated. Constructs a new FileItem.
 
Method Summary
protected  void finalize()
          Deprecated. Removes the file contents from the temporary storage.
 byte[] get()
          Deprecated. Returns the contents of the file as an array of bytes.
 java.lang.String getContentType()
          Deprecated. Returns the content type passed by the browser or null if not defined.
 java.lang.String getFileName()
          Deprecated. Returns the original filename in the user's filesystem.
 java.io.InputStream getInputStream()
          Deprecated. Returns an InputStream that can be used to retrieve the contents of the file.
 java.lang.String getName()
          Deprecated. Returns the original filename in the user's filesystem.
 java.io.OutputStream getOutputStream()
          Deprecated. Returns an OutputStream that can be used for storing the contents of the file.
 long getSize()
          Deprecated. Returns the size of the file.
 java.io.File getStoreLocation()
          Deprecated. Returns the File objects for the FileItems's data temporary location on the disk.
 java.io.InputStream getStream()
          Deprecated. Returns an InputStream that can be used to retrieve the contents of the file.
 java.lang.String getString()
          Deprecated. Returns the contents of the file as a String, using default encoding.
 java.lang.String getString(java.lang.String encoding)
          Deprecated. Returns the contents of the file as a String, using specified encoding.
 boolean inMemory()
          Deprecated. Provides a hint if the file contents will be read from memory.
static FileItem newInstance(java.lang.String path, java.lang.String name, java.lang.String contentType, int requestSize)
          Deprecated. Instantiates a FileItem.
 void write(java.lang.String file)
          Deprecated. A convenience method to write an uploaded file to disk.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_UPLOAD_SIZE_THRESHOLD

public static final int DEFAULT_UPLOAD_SIZE_THRESHOLD
Deprecated. 
The maximal size of request that will have it's elements stored in memory.

See Also:
Constant Field Values

fileName

protected java.lang.String fileName
Deprecated. 
The original filename in the user's filesystem.


contentType

protected java.lang.String contentType
Deprecated. 
The content type passed by the browser or null if not defined.


content

protected byte[] content
Deprecated. 
Cached contents of the file.


storeLocation

protected java.io.File storeLocation
Deprecated. 
Temporary storage location.


byteStream

protected java.io.ByteArrayOutputStream byteStream
Deprecated. 
Temporary storage for in-memory files.

Constructor Detail

FileItem

protected FileItem(java.lang.String fileName,
                   java.lang.String contentType)
Deprecated. 
Constructs a new FileItem.

Use newInstance(String,String,String,int) to instantiate FileItems.

Parameters:
fileName - The original filename in the user's filesystem.
contentType - The content type passed by the browser or null if not defined.
Method Detail

getName

public java.lang.String getName()
Deprecated. 
Returns the original filename in the user's filesystem. (implements DataSource method)

Specified by:
getName in interface javax.activation.DataSource
Returns:
The original filename in the user's filesystem.

getFileName

public java.lang.String getFileName()
Deprecated. 
Returns the original filename in the user's filesystem.

Returns:
The original filename in the user's filesystem.

getContentType

public java.lang.String getContentType()
Deprecated. 
Returns the content type passed by the browser or null if not defined. (implements DataSource method).

Specified by:
getContentType in interface javax.activation.DataSource
Returns:
The content type passed by the browser or null if not defined.

inMemory

public boolean inMemory()
Deprecated. 
Provides a hint if the file contents will be read from memory.

Returns:
True if the file contents will be read from memory.

getSize

public long getSize()
Deprecated. 
Returns the size of the file.

Returns:
The size of the file.

get

public byte[] get()
Deprecated. 
Returns the contents of the file as an array of bytes. If the contents of the file were not yet cached int the memory, they will be loaded from the disk storage and chached.

Returns:
The contents of the file as an array of bytes.

getString

public java.lang.String getString()
Deprecated. 
Returns the contents of the file as a String, using default encoding. This method uses get() to retrieve the contents of the file.

Returns:
The contents of the file.

getString

public java.lang.String getString(java.lang.String encoding)
                           throws java.io.UnsupportedEncodingException
Deprecated. 
Returns the contents of the file as a String, using specified encoding. This method uses get() to retireve the contents of the file.

Parameters:
encoding - The encoding to use.
Returns:
The contents of the file.
Throws:
UnsupportedEncodingException.
java.io.UnsupportedEncodingException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Deprecated. 
Returns an InputStream that can be used to retrieve the contents of the file. (implements DataSource method)

Specified by:
getInputStream in interface javax.activation.DataSource
Returns:
An InputStream that can be used to retrieve the contents of the file.
Throws:
Exception, - a generic exception.
java.io.IOException

getStream

public java.io.InputStream getStream()
                              throws java.io.IOException
Deprecated. 
Returns an InputStream that can be used to retrieve the contents of the file.

Returns:
An InputStream that can be used to retrieve the contents of the file.
Throws:
Exception, - a generic exception.
java.io.IOException

getStoreLocation

public java.io.File getStoreLocation()
Deprecated. 
Returns the File objects for the FileItems's data temporary location on the disk. Note that for FileItems that have their data stored in memory this method will return null. When handling large files, you can use File.renameTo(File) to move the file to new location without copying the data, if the source and destination locations reside within the same logical volume.

Returns:
A File.

finalize

protected void finalize()
Deprecated. 
Removes the file contents from the temporary storage.


getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Deprecated. 
Returns an OutputStream that can be used for storing the contents of the file. (implements DataSource method)

Specified by:
getOutputStream in interface javax.activation.DataSource
Returns:
an OutputStream that can be used for storing the contensts of the file.
Throws:
IOException.
java.io.IOException

newInstance

public static FileItem newInstance(java.lang.String path,
                                   java.lang.String name,
                                   java.lang.String contentType,
                                   int requestSize)
Deprecated. 
Instantiates a FileItem. It uses requestSize to decide what temporary storage approach the new item should take. The largest request that will have its items cached in memory can be configured in TurbineResources.properties in the entry named file.upload.size.threshold

Parameters:
path - A String.
name - The original filename in the user's filesystem.
contentType - The content type passed by the browser or null if not defined.
requestSize - The total size of the POST request this item belongs to.
Returns:
A FileItem.

write

public void write(java.lang.String file)
           throws java.lang.Exception
Deprecated. 
A convenience method to write an uploaded file to disk. The client code is not concerned whether or not the file is stored in memory, or on disk in a temporary location. They just want to write the uploaded file to disk.

Throws:
java.lang.Exception


Copyright © 2000-2005 Apache Software Foundation. All Rights Reserved.