T
- ファイル行オブジェクト。public abstract class AbstractFileLineWriter<T> extends Object implements FileLineWriter<T>
ファイルアクセス(データ書込)を行う3つのクラス(CSV、固定長、可変長) に共通する処理をまとめた抽象クラス。 ファイルの種類に対応するサブクラスが処理を行う。
使用例はFileLineWriter
を参照のこと。
ファイル取得処理は下記の手順で呼び出されるように実装すること。
コンストラクタと説明 |
---|
AbstractFileLineWriter(String fileName,
Class<T> clazz,
Map<String,ColumnFormatter> columnFormatterMap)
コンストラクタ。
|
修飾子とタイプ | メソッドと説明 |
---|---|
protected void |
checkWriteTrailer()
トレイラ部の処理が終わっているかどうかを判定する。
|
void |
closeFile()
ファイルクローズ処理。
|
protected String |
getColumn(T t,
int index)
ファイル行オブジェクトからカラムインデックスと一致する属性の値を取得する。
|
protected char[] |
getColumnEncloseChar()
カラムの囲み文字を取得する。
|
abstract char |
getDelimiter()
区切り文字を取得する。
|
abstract char |
getEncloseChar()
囲み文字を取得する。
|
protected Field[] |
getFields()
ファイル行オブジェクトのField情報(Annotation)を格納する変数を取得する。
|
String |
getFileName()
ファイル名を取得する。
|
protected String |
getLineFeedChar()
行区切り文字を設定する。
|
protected Method[] |
getMethods()
ファイル行オブジェクトのField情報に対応するgetterメソッドを格納する変数を取得する。
|
protected Writer |
getWriter()
ファイルアクセス(出力)用の文字ストリームを取得する。
|
protected void |
init()
初期化処理を行う。
|
protected boolean |
isCheckByte(int columnByte)
対象カラムに対するバイト数チェックを行うかを返す。
|
protected boolean |
isCheckByte(OutputFileColumn outputFileColumn)
対象カラムに対するバイト数チェックを行うかを返す。
|
protected boolean |
isCheckColumnAnnotationCount()
ファイル行オブジェクトにアノテーションが設定されている事をチェックするかどうかを返す。
|
protected boolean |
isCheckEncloseChar()
囲み文字が設定されていない事をチェックするかどうかを返す。
|
void |
printDataLine(T t)
データ部への書き込み処理。
|
void |
printHeaderLine(List<String> headerLine)
ヘッダ部への書込み処理。
|
void |
printTrailerLine(List<String> trailerLine)
トレイラ部への書込み処理。
|
void |
setColumnFormatterMap(Map<String,ColumnFormatter> columnFormatterMap)
カラムフォーマット(ファイル書込)処理を格納するマップを取得する。
|
protected void |
setLineFeedChar(String lineFeedChar)
行区切り文字を設定する。
|
protected void |
setWriteData(boolean writeData)
データ部の出力が開始されているかどうかを判定するフラグ。
|
public AbstractFileLineWriter(String fileName, Class<T> clazz, Map<String,ColumnFormatter> columnFormatterMap)
@FileFormat
アノテーションの設定チェックする。 @FileFormat
アノテーションが設定されていない場合は非検査例外をスローする。fileName
- ファイル名clazz
- パラメータクラスcolumnFormatterMap
- テキスト取得ルールprotected void init()
public void printHeaderLine(List<String> headerLine)
printHeaderLine
インタフェース内 FileLineWriter<T>
headerLine
- ヘッダ部へ書き込む文字列のリストpublic void printDataLine(T t)
printDataLine
インタフェース内 FileLineWriter<T>
t
- データ部へ書き込むファイル行オブジェクトpublic void printTrailerLine(List<String> trailerLine)
printTrailerLine
インタフェース内 FileLineWriter<T>
trailerLine
- トレイラ部へ書き込む文字列のリストpublic void closeFile()
closeFile
インタフェース内 FileLineWriter<T>
protected String getColumn(T t, int index)
ファイル行オブジェクトからカラムインデックスと一致する属性の値を取得する。
属性を取得する際、ファイル行オブジェクトのアノテーションの記述により 以下の処理を行う。
t
- ファイル行オブジェクトindex
- カラムのインデックスpublic String getFileName()
protected String getLineFeedChar()
protected void setLineFeedChar(String lineFeedChar)
行区切り文字
- public void setColumnFormatterMap(Map<String,ColumnFormatter> columnFormatterMap)
columnFormatterMap
- カラムフォーマット(ファイル書込)を格納するマップprotected Writer getWriter()
protected Field[] getFields()
protected Method[] getMethods()
protected void setWriteData(boolean writeData)
writeData
- フラグprotected void checkWriteTrailer()
public abstract char getDelimiter()
public abstract char getEncloseChar()
protected boolean isCheckByte(OutputFileColumn outputFileColumn)
固定長ファイル形式の場合は常にtrue
を返却してバイト数チェックを行う。
可変長、CSV形式でbytes
が指定されているときには trueを返却しバイト数チェックを行う。
outputFileColumn
- 対象カラムのOutputFileColumn情報protected boolean isCheckByte(int columnByte)
columnByte
- 対象カラムのバイト数protected boolean isCheckEncloseChar()
protected boolean isCheckColumnAnnotationCount()
protected char[] getColumnEncloseChar()
Copyright © 2014 NTT DATA Corporation.