org.apache.commons.fileupload
クラス DefaultFileItem

java.lang.Object
  拡張org.apache.commons.fileupload.DefaultFileItem
すべての実装インタフェース:
FileItem, Serializable

public class DefaultFileItem
extends Object
implements FileItem

FileItem インターフェイスの標準実装です。

The default implementation of the {@link org.apache.commons.fileupload.FileItem FileItem} interface.

DiskFileUpload からこのクラスインスタンスを取得した後 (#parseRequest(javax.servlet.http.HttpServletRequest)) を参照)、 get() メソッドを使ってすべてのファイルの内容を(メモリ上に)取得するか、 getInputStream() メソッドを使って InputStream を取得し、メモリ上に展開することなく ファイルを処理する(大きなファイルを扱う場合に有用)かを選択することができます。

After retrieving an instance of this class from a {@link org.apache.commons.fileupload.DiskFileUpload DiskFileUpload} instance (see {@link org.apache.commons.fileupload.DiskFileUpload #parseRequest(javax.servlet.http.HttpServletRequest)}), you may either request all contents of file at once using {@link #get()} or request an {@link java.io.InputStream InputStream} with {@link #getInputStream()} and process the file without attempting to load it into memory, which may come handy with large files.

バージョン:
$Id: DefaultFileItem.java,v 1.5 2004/04/07 04:00:48 hioki Exp $
作成者:
Rafal Krzewski, Sean Legassick, Jason van Zyl, John McNally, Martin Cooper, Sean C. Sullivan
関連項目:
直列化された形式
翻訳者:
日置 聡
校正者:
入江 弘憲
翻訳状況:
校了

フィールドの概要
private  byte[] cachedContent
          キャッシュされたファイルの内容。
private  String contentType
          ブラウザによって付加されたコンテントタイプ。
private static int counter
          固有の識別子を生成するために使用されるカウンタ。
private  DeferredFileOutputStream dfos
          このアイテムの出力ストリーム。
private  String fieldName
          ブラウザによって付加されたフォームフィールド名。
private  String fileName
          ユーザのファイルシステム上でのオリジナルのファイル名。
private  boolean isFormField
          このアイテムが単純なフォームフィールドかどうか。
private  File repository
          ディスク上に保持する場合にアップロードファイルが保存されるディレクトリ。
private  int sizeThreshold
          アップロードファイルをディスク上に保持するかどうかの閾値。
 
コンストラクタの概要
(パッケージプライベート) DefaultFileItem(String fieldName, String contentType, boolean isFormField, String fileName, int sizeThreshold, File repository)
          新規 DefaultFileItem インスタンスを生成します。
 
メソッドの概要
 void delete()
          関係する一時ディスク領域も含むストレージ上のファイルアイテムを削除します。
protected  void finalize()
          一時領域からファイルの内容を削除します。
 byte[] get()
          ファイルの内容をバイト配列で返します。
 String getContentType()
          ブラウザによって付加されたコンテントタイプを返します。
 String getFieldName()
          ファイルアイテムに対応したマルチパートフォームフィールド名を返します。
 InputStream getInputStream()
          ファイルの内容を取得するための InputStream を返します。
 String getName()
          クライアントのファイルシステム上でのオリジナルのファイル名を返します。
 OutputStream getOutputStream()
          ファイルの内容を保持するための OutputStream を返します。
 long getSize()
          ファイルアイテムのサイズを返します。
 File getStoreLocation()
          一時領域に保持されている FileItem のデータを示す File オブジェクトを返します。
 String getString()
          デフォルトのキャラクタエンコーディングを使用してファイルの内容の文字列表現を返します。
 String getString(String encoding)
          指定されたエンコーディングを使用してファイルの内容の文字列表現を返します。
protected  File getTempFile()
          設定されたリポジトリパス内の固有名称の一時ファイルを表す File を作成して返します。
private static String getUniqueId()
          このクラスをロードするクラスローダ内で固有の(しかしランダムに見えない)識別子を返します。
 boolean isFormField()
          FileItem インスタンスが単純なフォームフィールドを示すかどうかを判断します。
 boolean isInMemory()
          ファイルの内容をメモリ上から読み込むことができるかどうかを示します。
 void setFieldName(String fieldName)
          このファイルアイテムを参照するためのフィールド名を設定します。
 void setFormField(boolean state)
          FileItem インスタンスが単純なフォームフィールドを示すかどうかを設定します。
 void write(File file)
          アップロードアイテムをディスクに書き出すための簡易メソッドです。
 
クラス java.lang.Object から継承したメソッド
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

counter

private static int counter
固有の識別子を生成するために使用されるカウンタ。
Counter used in unique identifier generation.


fieldName

private String fieldName
ブラウザによって付加されたフォームフィールド名。
The name of the form field as provided by the browser.


contentType

private String contentType
ブラウザによって付加されたコンテントタイプ。 定義されていない場合には null 。
The content type passed by the browser, or null if not defined.


isFormField

private boolean isFormField
このアイテムが単純なフォームフィールドかどうか。
Whether or not this item is a simple form field.


fileName

private String fileName
ユーザのファイルシステム上でのオリジナルのファイル名。
The original filename in the user's filesystem.


sizeThreshold

private int sizeThreshold
アップロードファイルをディスク上に保持するかどうかの閾値。
The threshold above which uploads will be stored on disk.


repository

private File repository
ディスク上に保持する場合にアップロードファイルが保存されるディレクトリ。
The directory in which uploaded files will be stored, if stored on disk.


cachedContent

private byte[] cachedContent
キャッシュされたファイルの内容。
Cached contents of the file.


dfos

private DeferredFileOutputStream dfos
このアイテムの出力ストリーム。
Output stream for this item.

コンストラクタの詳細

DefaultFileItem

DefaultFileItem(String fieldName,
                String contentType,
                boolean isFormField,
                String fileName,
                int sizeThreshold,
                File repository)
新規 DefaultFileItem インスタンスを生成します。
Constructs a new DefaultFileItem instance.

パラメータ:
fieldName - フォームフィールド名。
The name of the form field.
contentType - ブラウザによって付加されたコンテントタイプ。 定義されていない場合には null
The content type passed by the browser or null if not specified.
isFormField - このアイテムがアップロードファイルではなく 単純なフォームフィールドかどうか。
Whether or not this item is a plain form field, as opposed to a file upload.
fileName - ユーザのファイルシステム上でのオリジナルのファイル名。 定義されていない場合には null
The original filename in the user's filesystem, or null if not specified.
sizeThreshold - このアイテムがメモリ上に保持されるか、ファイルとして保存されるかの バイト単位の閾値。
The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file.
repository - アイテムのサイズが閾値を超えた場合にファイルを生成し 保存するディレクトリの位置。
The data repository, which is the directory in which files will be created, should the item size exceed the threshold.
メソッドの詳細

getInputStream

public InputStream getInputStream()
                           throws IOException
ファイルの内容を取得するための InputStream を返します。
Returns an {@link java.io.InputStream InputStream} that can be used to retrieve the contents of the file.

定義:
インタフェース FileItem 内の getInputStream
戻り値:
ファイルの内容を取得するための InputStream
{@link java.io.InputStream InputStream} that can be used to retrieve the contents of the file.
例外:
IOException - エラーが発生した場合。
if an error occurs.

getContentType

public String getContentType()
ブラウザによって付加されたコンテントタイプを返します。 定義されていない場合には null を返します。
Returns the content type passed by the browser or null if not defined.

定義:
インタフェース FileItem 内の getContentType
戻り値:
ブラウザによって付加されたコンテントタイプ。 定義されていない場合には null
The content type passed by the browser or null if not defined.

getName

public String getName()
クライアントのファイルシステム上でのオリジナルのファイル名を返します。
Returns the original filename in the client's filesystem.

定義:
インタフェース FileItem 内の getName
戻り値:
クライアントのファイルシステム上でのオリジナルのファイル名。
The original filename in the client's filesystem.

isInMemory

public boolean isInMemory()
ファイルの内容をメモリ上から読み込むことができるかどうかを示します。
Provides a hint as to whether or not the file contents will be read from memory.

定義:
インタフェース FileItem 内の isInMemory
戻り値:
true ファイルの内容をメモリ上から読み込むことができる場合; false その他の場合。
true if the file contents will be read from memory; false otherwise.

getSize

public long getSize()
ファイルアイテムのサイズを返します。
Returns the size of the file.

定義:
インタフェース FileItem 内の getSize
戻り値:
ファイルアイテムのバイト単位のサイズ。
The size of the file, in bytes.

get

public byte[] get()
ファイルの内容をバイト配列で返します。 ファイルの内容がまだメモリ上にキャッシュされていない場合、 ディスクストレージからロードし、キャッシュします。
Returns the contents of the file as an array of bytes. If the contents of the file were not yet cached in memory, they will be loaded from the disk storage and cached.

定義:
インタフェース FileItem 内の get
戻り値:
ファイルの内容を示すバイト配列。
The contents of the file as an array of bytes.

getString

public String getString(String encoding)
                 throws UnsupportedEncodingException
指定されたエンコーディングを使用してファイルの内容の文字列表現を返します。 このメソッドはファイルの内容を取得するために get() メソッドを使用します。
Returns the contents of the file as a String, using the specified encoding. This method uses {@link #get()} to retrieve the contents of the file.

定義:
インタフェース FileItem 内の getString
パラメータ:
encoding - 使用するキャラクタエンコーディング。
The character encoding to use.
戻り値:
ファイルの内容の文字列表現。
The contents of the file, as a string.
例外:
UnsupportedEncodingException - 指定されたエンコーディングが利用できなかった場合。
if the requested character encoding is not available.

getString

public String getString()
デフォルトのキャラクタエンコーディングを使用してファイルの内容の文字列表現を返します。 このメソッドはファイルの内容を取得するために get() メソッドを使用します。
Returns the contents of the file as a String, using the default character encoding. This method uses {@link #get()} to retrieve the contents of the file.

定義:
インタフェース FileItem 内の getString
戻り値:
ファイルの内容の文字列表現。
@return The contents of the file, as a string.

write

public void write(File file)
           throws Exception
アップロードアイテムをディスクに書き出すための簡易メソッドです。 クライアントコードはアイテムがメモリに保持されているか、ディスクの一時領域に保持されているかを考慮しません。 アップロードアイテムをファイルに書き出すことだけを考えます。
A convenience method to write an uploaded item to disk. The client code is not concerned with whether or not the item is stored in memory, or on disk in a temporary location. They just want to write the uploaded item to a file.

この実装はもしアイテムがディスク上に展開されている場合、 最初にアップロードアイテムを指定された名称のファイルに変更する事を試みます。 それ以外の場合にはデータを指定されたファイルにコピーします。

This implementation first attempts to rename the uploaded item to the specified destination file, if the item was originally written to disk. Otherwise, the data will be copied to the specified file.

このメソッドは、1つのアイテムについて最初に実行された1度だけ、動作することが保証されます。 (1度処理を行った後には)このメソッドは一時ファイルの名称を変更してしまうので、 次にコピーまたは名称の変更をしようとしても、そのファイルはもう既に利用できません。

This method is only guaranteed to work once, the first time it is invoked for a particular item. This is because, in the event that the method renames a temporary file, that file will no longer be available to copy or rename again at a later time.

定義:
インタフェース FileItem 内の write
パラメータ:
file - アップロードアイテムの出力先となる File
The File into which the uploaded item should be stored.
例外:
Exception - エラーが発生した場合。
if an error occurs.

delete

public void delete()
関係する一時ディスク領域も含むストレージ上のファイルアイテムを削除します。 FileItem インスタンスがガベージコレクションにかかった時にこのストレージは削除されますが、 このメソッドは早く確実に削除を実施し、システムリソースを保護します。
Deletes the underlying storage for a file item, including deleting any associated temporary disk file. Although this storage will be deleted automatically when the FileItem instance is garbage collected, this method can be used to ensure that this is done at an earlier time, thus preserving system resources.

定義:
インタフェース FileItem 内の delete

getFieldName

public String getFieldName()
ファイルアイテムに対応したマルチパートフォームフィールド名を返します。
Returns the name of the field in the multipart form corresponding to this file item.

定義:
インタフェース FileItem 内の getFieldName
戻り値:
フォームフィールド名。
The name of the form field.
関連項目:
setFieldName(java.lang.String)

setFieldName

public void setFieldName(String fieldName)
このファイルアイテムを参照するためのフィールド名を設定します。
Sets the field name used to reference this file item.

定義:
インタフェース FileItem 内の setFieldName
パラメータ:
fieldName - フォームフィールド名。
The name of the form field.
関連項目:
getFieldName()

isFormField

public boolean isFormField()
FileItem インスタンスが単純なフォームフィールドを示すかどうかを判断します。
Determines whether or not a FileItem instance represents a simple form field.

定義:
インタフェース FileItem 内の isFormField
戻り値:
true インスタンスが単純なフォームフィールドを示す場合; false インスタンスがアップロードされたファイルを示す場合。
true if the instance represents a simple form field; false if it represents an uploaded file.
関連項目:
setFormField(boolean)

setFormField

public void setFormField(boolean state)
FileItem インスタンスが単純なフォームフィールドを示すかどうかを設定します。
Specifies whether or not a FileItem instance represents a simple form field.

定義:
インタフェース FileItem 内の setFormField
パラメータ:
state - true インスタンスが単純なフォームフィールドを示す場合; false インスタンスがアップロードされたファイルを示す場合。
true if the instance represents a simple form field; false if it represents an uploaded file.
関連項目:
isFormField()

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
ファイルの内容を保持するための OutputStream を返します。
Returns an {@link java.io.OutputStream OutputStream} that can be used for storing the contents of the file.

定義:
インタフェース FileItem 内の getOutputStream
戻り値:
ファイルの内容を保持するための OutputStream
An {@link java.io.OutputStream OutputStream} that can be used for storing the contensts of the file.
例外:
IOException - エラーが発生した場合。
if an error occurs.

getStoreLocation

public File getStoreLocation()
一時領域に保持されている FileItem のデータを示す File オブジェクトを返します。 FileItem がデータをメモリ上に保持している場合には、 このメソッドは null を返します。 大きなファイルを扱う際には、もし一時領域と移動先の論理ボリュームが同じなら File.renameTo(java.io.File) を使ってデータのコピーを行うことなく新しい位置に移動することができます。
Returns the {@link java.io.File} object for the FileItem's data's 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 {@link java.io.File#renameTo(java.io.File)} to move the file to new location without copying the data, if the source and destination locations reside within the same logical volume.

戻り値:
データファイル。データがメモリ上に保持されている場合には null
The data file, or null if the data is stored in memory.

finalize

protected void finalize()
一時領域からファイルの内容を削除します。
Removes the file contents from the temporary storage.


getTempFile

protected File getTempFile()
設定されたリポジトリパス内の固有名称の一時ファイルを表す File を作成して返します。
Creates and returns a {@link java.io.File File} representing a uniquely named temporary file in the configured repository path.

戻り値:
一時領域内の File
The {@link java.io.File File} to be used for temporary storage.

getUniqueId

private static String getUniqueId()
このクラスをロードするクラスローダ内で固有の(しかしランダムに見えない)識別子を返します。
Returns an identifier that is unique within the class loader used to load this class, but does not have random-like apearance.

戻り値:
(ランダムに見えない)インスタンス識別子の文字列。
A String with the non-random looking instance identifier.


このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation