FileWriterPattern
FileWriterPattern パターンは、テキスト・データをファイルに書き込むために使用されます。
サポートされるクラス
TextFileWriter クラスは、指定されたファイルを開いてストリング・データを書き込むための論理を提供します。 このファイルは、指定されたプロパティーに応じて、付加モードまたは上書きモードで開かれます。 ジョブ再始動時には、ファイルは常に付加モードで開かれます。
TextFileWriter ファイル名を JobStepContext から動的に設定するには、次の 2 つの方法があります。
- Compute Grid によって定義された、よく知られた単一のジョブ・レベル・プロパティーを使用します。以下の例では、次のようになっています。
上記の 例で、"/my/fileName" 値を TextFileWriter 初期化の前に設定すると、この値が TextFileWriter によってファイル名として使用されます。JobStepContext ctx = JobStepContextMgr.getContext(); Properties jobProps = ctx.getJobLevelProperties(); jobProps.set(TextFileWriter. FILENAME_JOBSTEPCONTEXT_DEFAULT_PROPERTY_NAME, "/my/fileName");
- BDS ライター・レベル xJCL プロパティーによって定義された、独自のカスタム・プロパティーを使用します。この方法は、2 つのライターがあり、それぞれが異なるファイル名を必要とする場合に使用します。この方法では、com.ibm.websphere.batch.devframework.datastreams.patterns.TextFileWriter.FILENAME.xjcl.custom.property.name という名前の BDS レベル xJCL プロパティーを使用して、JobStepContext プロパティー名を識別します。以下に例を示します。
xJCL <bds> <logical-name>outputStream</logical-name> <impl-class>com.ibm.websphere.batch.devframework.datastreams.patterns.TextFileWriter</impl-class> <props> <prop name="PATTERN_IMPL_CLASS" value="mypkg.MyWriter"/> <prop name="FILENAME" value="/my/staticFileName.txt"/> <!-- This will take affect if the dynamic config isn't set. --> <prop name="AppendJobIdToFileName" value="true"/> <!-- Existing options are still usable with dynamically-determined filenames --> <prop name="debug" value="true"/> <prop name="com.ibm.websphere.batch.devframework.datastreams.patterns.TextFileWriter.FILENAME.xjcl.custom.property.name" value="my.bds.specific.property.name"/> </props> </bds> </batch-data-streams> </job-step>
最初の方法と同じように、ジョブ・レベル・プロパティーを TextFileWriter 初期化の前に設定します。以下に例を示します。JobStepContext ctx = JobStepContextMgr.getContext(); Properties jobProps = ctx.getJobLevelProperties(); jobProps.set("my.bds.specific.property.name", "/my/fileName");
必須プロパティー
以下は、このパターンの必須のプロパティーです。
プロパティー名 | 値 |
---|---|
PATTERN_IMPL_CLASS | FileWriterPattern インターフェースを実装するクラス |
FILENAME | 入力ファイルへの完全パス |
オプション・プロパティー
以下は、このパターンのオプションのプロパティーです。
プロパティー名 | 値 | 説明 |
---|---|---|
debug | true または false (デフォルトは false) | このバッチ・データ・ストリームに対する詳細トレースを使用可能にします。 |
EnablePerformanceMeasurement | true または false (デフォルトは false) | GenericXDBatchStep を使用している場合に、バッチ・データ・ストリームおよび processRecord メソッドに費やされた合計時間を計算します。 |
EnableDetailedPerformanceMeasurement | true または false (デフォルトは false) | バッチ・データ・ストリームの各メソッドで費やされた時間のより詳細な明細を提供します。 |
file.encoding | ファイルのエンコード | 例えば、8859_1 です。 |
AppendJobldToFileName | true または false (デフォルトは false) | ファイルをロードする前にファイル名にジョブ ID を付加します。 |
append | true または false (デフォルトは true) | ファイルを付加モードで開くかどうかを決定します。
重要: 再始動時には、ファイルは常に付加モードで開かれます。
|
インターフェース定義
public interface FileWriterPattern {
/**
* Invoked during step setup phase
* @param props
*/
public void initialize(Properties props);
/**
* This method should write the given record
* object to the bufferedwriter.
* @param out
* @param record
* @throws IOException
*/
public void writeRecord(BufferedWriter out, Object record) throws IOException;
/**
* This method is invoked only once just after the bufferedwriter
* is opened. It should be used to write any header information
* @param out
* @throws IOException
*/
public void writeHeader(BufferedWriter out) throws IOException;
/**
* This method can be optionally called during process step to explicity
* initialize and write the header.
* @param header
* @throws IOException
*/
public void writeHeader(BufferedWriter out, Object header) throws IOException;
}
xJCL のサンプル
<batch-data-streams>
<bds>
<logical-name>outputStream</logical-name>
<props>
<prop name="PATTERN_IMPL_CLASS" value="com.ibm.websphere.batch.samples.tests.bds.EchoWriter"/>
<prop name="file.encoding" value="8859_1"/>
<prop name="FILENAME" value="/opt/txlist.txt" />
<prop name="debug" value="true"/>
</props>
<impl-class>com.ibm.websphere.batch.devframework.datastreams.patterns.TextFileWriter</impl-class>
</bds>
</batch-data-streams>