org.apache.commons.fileupload
インタフェース FileItem

すべてのスーパーインタフェース:
Serializable
既知の実装クラスの一覧:
DefaultFileItem

public interface FileItem
extends Serializable

このクラスはクライアントから受け取る multipart/form-data のPOSTリクエスト内のファイルまたはアイテムを表現したものです。

This class represents a file or form item that was received within a multipart/form-data POST request.

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

After retrieving an instance of this class from a {@link org.apache.commons.fileupload.FileUpload FileUpload} instance (see {@link org.apache.commons.fileupload.FileUpload #parseRequest(javax.servlet.http.HttpServletRequest)}), you may either request all contents of the 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.

このインターフェイスは(めったに使われない依存関係を避けるため) javax.activation.DataSource を継承していませんが、 定義されたいくつかのメソッドはこのインターフェイスとまったく同じ名称で定義されています。 そのため、このインターフェイスの実装クラスに最低限の修正を加えることで javax.activation.DataSource も実装することができます。

While this interface does not extend javax.activation.DataSource per se (to avoid a seldom used dependency), several of the defined methods are specifically defined with the same signatures as methods in that interface. This allows an implementation of this interface to also implement javax.activation.DataSource with minimal additional work.

バージョン:
$Id: FileItem.java,v 1.5 2004/04/13 09:29:57 hioki Exp $
作成者:
Rafal Krzewski, Sean Legassick, Jason van Zyl, Martin Cooper
翻訳者:
日置 聡
校正者:
入江 弘憲
翻訳状況:
校了

メソッドの概要
 void delete()
          関係する一時ディスク領域も含むストレージ上のファイルアイテムを削除します。
 byte[] get()
          ファイルアイテムの内容をバイト配列で返します。
 String getContentType()
          ブラウザによって付加されたコンテントタイプを返します。
 String getFieldName()
          ファイルアイテムに対応したマルチパートフォームフィールド名を返します。
 InputStream getInputStream()
          ファイルの内容を取得するための InputStream を返します。
 String getName()
          ブラウザ(または他のクライアントソフトウェア)によって渡された クライアントのファイルシステム上でのオリジナルのファイル名を返します。
 OutputStream getOutputStream()
          ファイルの内容を保持するための OutputStream を返します。
 long getSize()
          ファイルアイテムのサイズを返します。
 String getString()
          デフォルトのキャラクタエンコーディングを使用してファイルアイテムの内容の文字列表現を返します。
 String getString(String encoding)
          指定されたエンコーディングを使用してファイルアイテムの内容の文字列表現を返します。
 boolean isFormField()
          FileItem インスタンスが単純なフォームフィールドを示すかどうかを判断します。
 boolean isInMemory()
          ファイルの内容をメモリ上から読み込むことができるかどうかを示します。
 void setFieldName(String name)
          このファイルアイテムを参照するためのフィールド名を設定します。
 void setFormField(boolean state)
          FileItem インスタンスが単純なフォームフィールドを示すかどうかを設定します。
 void write(File file)
          アップロードアイテムをディスクに書き出すための簡易メソッドです。
 

メソッドの詳細

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.

戻り値:
ファイルの内容を取得するための InputStream
An {@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.

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

getName

public String getName()
ブラウザ(または他のクライアントソフトウェア)によって渡された クライアントのファイルシステム上でのオリジナルのファイル名を返します。 大体の場合、これはパス情報を除いた元のファイル名になります。 しかし、Operaブラウザ等のいくつかのクライアントではパス情報が含まれます。
Returns the original filename in the client's filesystem, as provided by the browser (or other client software). In most cases, this will be the base file name, without path information. However, some clients, such as the Opera browser, do include path information.

戻り値:
クライアントのファイルシステム上でのオリジナルのファイル名。
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.

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

getSize

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

戻り値:
ファイルアイテムのバイト単位のサイズ 。
The size of the file item, in bytes.

get

public byte[] get()
ファイルアイテムの内容をバイト配列で返します。
Returns the contents of the file item as an array of bytes.

戻り値:
ファイルアイテムの内容を示すバイト配列。
The contents of the file item as an array of bytes.

getString

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

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

getString

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

戻り値:
アイテムの内容の文字列表現。
The contents of the item, 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 method is not guaranteed to succeed if called more than once for the same item. This allows a particular implementation to use, for example, file renaming, where possible, rather than copying all of the underlying data, thus gaining a significant performance benefit.

パラメータ:
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.


getFieldName

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

戻り値:
フォームフィールド名。
The name of the form field.

setFieldName

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

パラメータ:
name - フォームフィールド名。
The name of the form field.

isFormField

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

戻り値:
true インスタンスが単純なフォームフィールドを示す場合; false インスタンスがアップロードされたファイルを示す場合。
true if the instance represents a simple form field; false if it represents an uploaded file.

setFormField

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

パラメータ:
state - true インスタンスが単純なフォームフィールドを示す場合; false インスタンスがアップロードされたファイルを示す場合。
true if the instance represents a simple form field; false if it represents an uploaded file.

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.

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


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