org.apache.commons.fileupload
クラス DeferredFileOutputStream

java.lang.Object
  拡張java.io.OutputStream
      拡張org.apache.commons.fileupload.ThresholdingOutputStream
          拡張org.apache.commons.fileupload.DeferredFileOutputStream

public class DeferredFileOutputStream
extends ThresholdingOutputStream

指定された閾値に達するまではデータをメモリ上に保持し、 閾値に達した場合にはディスク上に出力する出力ストリームです。 もし閾値に達することなくクローズされた場合には、データはディスクに全く書き込まれません。

An output stream which will retain data in memory until a specified threshold is reached, and only then commit it to disk. If the stream is closed before the threshold is reached, the data will not be written to disk at all.

バージョン:
$Id: DeferredFileOutputStream.java,v 1.5 2004/04/12 07:50:26 hioki Exp $
作成者:
Martin Cooper
翻訳者:
日置 聡
校正者:
入江 弘憲
翻訳状況:
校了

フィールドの概要
private  OutputStream currentOutputStream
          現在データの出力先となっている出力ストリーム。
private  FileOutputStream diskOutputStream
          閾値に達した後にデータが書き込まれる出力ストリーム。
private  ByteArrayOutputStream memoryOutputStream
          閾値に達するまでデータが書き込まれる出力ストリーム。
private  File outputFile
          閾値を超えた場合に出力先となるファイル。
 
クラス org.apache.commons.fileupload.ThresholdingOutputStream から継承したフィールド
 
コンストラクタの概要
DeferredFileOutputStream(int threshold, File outputFile)
          イベントのトリガーとなる閾値の値と、それを超えた場合にデータをセーブするファイルを指定して クラスのインスタンスを生成します。
 
メソッドの概要
 byte[] getData()
          データがメモリ上にある場合、出力ストリームをバイトの配列にして返します。
 File getFile()
          データがディスク上にある場合、出力ストリームを File にして返します。
protected  OutputStream getStream()
          現在使われている出力ストリームを返します。
 boolean isInMemory()
          出力ストリームがメモリを対象にしているかを判断します。
protected  void thresholdReached()
          現在使用している出力ストリームをメモリを対象にしているものからディスクを対象にするものに切り替えます。
 
クラス org.apache.commons.fileupload.ThresholdingOutputStream から継承したメソッド
checkThreshold, close, flush, getByteCount, getThreshold, isThresholdExceeded, write, write, write
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

memoryOutputStream

private ByteArrayOutputStream memoryOutputStream
閾値に達するまでデータが書き込まれる出力ストリーム。
The output stream to which data will be written prior to the theshold being reached.


diskOutputStream

private FileOutputStream diskOutputStream
閾値に達した後にデータが書き込まれる出力ストリーム。
The output stream to which data will be written after the theshold is reached.


currentOutputStream

private OutputStream currentOutputStream
現在データの出力先となっている出力ストリーム。 これは memoryOutputStreamdiskOutputStream のどちらかとなります。
The output stream to which data will be written at any given time. This will always be one of memoryOutputStream or diskOutputStream.


outputFile

private File outputFile
閾値を超えた場合に出力先となるファイル。
The file to which output will be directed if the threshold is exceeded.

コンストラクタの詳細

DeferredFileOutputStream

public DeferredFileOutputStream(int threshold,
                                File outputFile)
イベントのトリガーとなる閾値の値と、それを超えた場合にデータをセーブするファイルを指定して クラスのインスタンスを生成します。
Constructs an instance of this class which will trigger an event at the specified threshold, and save data to a file beyond that point.

パラメータ:
threshold - イベントのトリガーとなるバイトの値。
The number of bytes at which to trigger an event.
outputFile - 閾値を超えた場合にデータを保存するファイル。
The file to which data is saved beyond the threshold.
メソッドの詳細

getStream

protected OutputStream getStream()
                          throws IOException
現在使われている出力ストリームを返します。 これは閾値に対する状態によってメモリが対象、またはディスクが対象のものになります。
Returns the current output stream. This may be memory based or disk based, depending on the current state with respect to the threshold.

定義:
クラス ThresholdingOutputStream 内の getStream
戻り値:
現在使われている出力ストリーム。
The underlying output stream.
例外:
IOException - エラーが発生した場合。
if an error occurs.

thresholdReached

protected void thresholdReached()
                         throws IOException
現在使用している出力ストリームをメモリを対象にしているものからディスクを対象にするものに切り替えます。 これはメモリ上に保持するにはデータが大きすぎると考え、ディスク上に保存する方に切り替える分岐点です。
Switches the underlying output stream from a memory based stream to one that is backed by disk. This is the point at which we realise that too much data is being written to keep in memory, so we elect to switch to disk-based storage.

定義:
クラス ThresholdingOutputStream 内の thresholdReached
例外:
IOException - エラーが発生した場合。
if an error occurs.

isInMemory

public boolean isInMemory()
出力ストリームがメモリを対象にしているかを判断します。
Determines whether or not the data for this output stream has been retained in memory.

戻り値:
true データがメモリを使用している場合; false それ以外の場合。
true if the data is available in memory; false otherwise.

getData

public byte[] getData()
データがメモリ上にある場合、出力ストリームをバイトの配列にして返します。 データがファイルに出力されている場合には、このメソッドは null を返します。
Returns the data for this output stream as an array of bytes, assuming that the data has been retained in memory. If the data was written to disk, this method returns null.

戻り値:
出力ストリームのデータ。 データが取得できなかった場合には null
The data for this output stream, or null if no such data is available.

getFile

public File getFile()
データがディスク上にある場合、出力ストリームを File にして返します。 データがメモリ上にある場合には、このメソッドは null を返します。
Returns the data for this output stream as a File, assuming that the data was written to disk. If the data was retained in memory, this method returns null.

戻り値:
出力ストリームのファイル。 ファイルが存在しかった場合には null
[訳注: 現状コンストラクタで指定したFileを常に返します。]
The file for this output stream, or null if no such file exists.


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