001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.fukurou.process;
017
018import org.opengion.fukurou.system.OgRuntimeException ;         // 6.4.2.0 (2016/01/29)
019import org.opengion.fukurou.system.OgCharacterException ;                                       // 6.5.0.1 (2016/10/21)
020import org.opengion.fukurou.system.Closer ;
021import org.opengion.fukurou.system.LogWriter;
022import org.opengion.fukurou.util.Argument;
023import org.opengion.fukurou.util.StringUtil;
024import org.opengion.fukurou.util.FileUtil;
025
026import java.util.Map ;
027import java.util.concurrent.ConcurrentMap;                                      // 6.4.3.4 (2016/03/11)
028import java.util.concurrent.ConcurrentHashMap;                          // 6.4.3.1 (2016/02/12) refactoring
029import java.util.LinkedHashMap ;
030import java.nio.charset.CharacterCodingException;                       // 6.3.1.0 (2015/06/28)
031
032import java.io.File;
033import java.io.BufferedReader;
034import java.io.IOException;
035
036/**
037 * Process_TableDiffは、ファイルから読み取った内容を、LineModel に設定後、
038 * 下流に渡す、FirstProcess インターフェースの実装クラスです。
039 *
040 * DBTableModel 形式のファイルを読み取って、各行を LineModel にセットして、
041 * 下流(プロセスチェインのデータは上流から下流に渡されます。)に渡します。
042 *
043 * 引数文字列中にスペースを含む場合は、ダブルコーテーション("") で括って下さい。
044 * 引数文字列の 『=』の前後には、スペースは挟めません。必ず、-key=value の様に
045 * 繋げてください。
046 *
047 * @og.formSample
048 *  Process_TableDiff -infile1=INFILE -infile2=INFILE2 -action=DIFF1 -encode=UTF-8 -columns=AA,BB,CC
049 *
050 *    -infile1=入力ファイル名1    :入力ファイル名1
051 *    -infile2=入力ファイル名2    :入力ファイル名2
052 *    -action=比較結果の方法      :ONLY,DIFF,INTERSEC
053 *   [-sep1=セパレータ文字      ] :区切り文字1(初期値:タブ)
054 *   [-sep2=セパレータ文字      ] :区切り文字2(初期値:タブ)
055 *   [-encode1=文字エンコード   ] :入力ファイルのエンコードタイプ1
056 *   [-encode2=文字エンコード   ] :入力ファイルのエンコードタイプ2
057 *   [-columns=読み取りカラム名 ] :入力カラム名(CSV形式)
058 *   [-keyClms=比較するカラム名 ] :比較する列の基準カラム名(CSV形式)
059 *   [-diffClms=比較するカラム名] :比較するカラム名(CSV形式)
060 *   [-display=[false/true]     ] :結果を標準出力に表示する(true)かしない(false)か(初期値:false[表示しない])
061 *   [-debug=[false/true]       ] :デバッグ情報を標準出力に表示する(true)かしない(false)か(初期値:false[表示しない])
062 *
063 * @og.rev 4.2.3.0 (2008/05/26) 新規作成
064 *
065 * @version  4.0
066 * @author   Kazuhiko Hasegawa
067 * @since    JDK5.0,
068 */
069public class Process_TableDiff extends AbstractProcess implements FirstProcess {
070        private static final String ENCODE = System.getProperty("file.encoding");
071
072        private char                    separator1      = TAB;  // 6.0.2.5 (2014/10/31) TAB を char 化
073        private char                    separator2      = TAB;  // 6.0.2.5 (2014/10/31) TAB を char 化
074        private String                  infile1         ;
075        private String                  encode1         ;               // 6.3.1.0 (2015/06/28) エラー時のメッセージに使う。
076        private String                  infile2         ;
077        private BufferedReader  reader1         ;
078        private LineModel               model           ;
079        private String                  line            ;
080        private int[]                   clmNos          ;               // ファイルのヘッダーのカラム番号
081        private int[]                   keyClmNos       ;               // 比較する列の基準カラム名のカラム番号
082        private int[]                   diffClmNos      ;               // 比較するカラム名のカラム番号
083        private String                  actCmnd         ;               // action から名称変更
084        private boolean                 display         ;               // 表示しない
085        private boolean                 debug           ;               // 表示しない
086        private boolean                 nameNull        ;               // 0件データ時 true
087
088        /** 6.4.3.1 (2016/02/12) PMD refactoring. HashMap → ConcurrentHashMap に置き換え。  */
089        private final ConcurrentMap<String,String> file2Map = new ConcurrentHashMap<>();        // 4.3.1.1 (2008/08/23) final化
090
091        private int                             inCount1        ;
092        private int                             inCount2        ;
093        private int                             outCount        ;
094
095        /** staticイニシャライザ後、読み取り専用にするので、ConcurrentHashMap を使用しません。 */
096        private static final Map<String,String> MUST_PROPARTY   ;               // [プロパティ]必須チェック用 Map
097        /** staticイニシャライザ後、読み取り専用にするので、ConcurrentHashMap を使用しません。 */
098        private static final Map<String,String> USABLE_PROPARTY ;               // [プロパティ]整合性チェック Map
099
100        static {
101                MUST_PROPARTY = new LinkedHashMap<>();
102                MUST_PROPARTY.put( "infile1",   "入力ファイル名1 (必須)" );
103                MUST_PROPARTY.put( "infile2",   "入力ファイル名2 (必須)" );
104                MUST_PROPARTY.put( "action",            "(必須)ONLY,DIFF,INTERSEC" );
105                MUST_PROPARTY.put( "keyClms",   "比較する列の基準カラム名(必須)(CSV形式)" );
106                MUST_PROPARTY.put( "diffClms",  "比較するカラム名(必須)(CSV形式)" );
107
108                USABLE_PROPARTY = new LinkedHashMap<>();
109                USABLE_PROPARTY.put( "sep1",                    "区切り文字1 (初期値:タブ)" );
110                USABLE_PROPARTY.put( "sep2",                    "区切り文字2 (初期値:タブ)" );
111                USABLE_PROPARTY.put( "encode1",         "入力ファイルのエンコードタイプ1" );
112                USABLE_PROPARTY.put( "encode2",         "入力ファイルのエンコードタイプ2" );
113                USABLE_PROPARTY.put( "columns",         "入力カラム名(CSV形式)" );
114                USABLE_PROPARTY.put( "display",         "結果を標準出力に表示する(true)かしない(false)か" +
115                                                                                        CR + " (初期値:false:表示しない)" );
116                USABLE_PROPARTY.put( "debug",           "デバッグ情報を標準出力に表示する(true)かしない(false)か" +
117                                                                                        CR + " (初期値:false:表示しない)" );
118        }
119
120        /**
121         * デフォルトコンストラクター。
122         * このクラスは、動的作成されます。デフォルトコンストラクターで、
123         * super クラスに対して、必要な初期化を行っておきます。
124         *
125         */
126        public Process_TableDiff() {
127                super( "org.opengion.fukurou.process.Process_TableDiff",MUST_PROPARTY,USABLE_PROPARTY );
128        }
129
130        /**
131         * プロセスの初期化を行います。初めに一度だけ、呼び出されます。
132         * 初期処理(ファイルオープン、DBオープン等)に使用します。
133         *
134         * @og.rev 6.3.1.0 (2015/06/28) nioを使用すると UTF-8とShuft-JISで、エラーになる。
135         *
136         * @param   paramProcess データベースの接続先情報などを持っているオブジェクト
137         */
138        public void init( final ParamProcess paramProcess ) {
139                final Argument arg = getArgument();
140
141                infile1                         = arg.getProparty( "infile1" );
142                encode1                         = arg.getProparty( "encode1",ENCODE );
143                infile2                         = arg.getProparty( "infile2" );
144                actCmnd                         = arg.getProparty( "action"  );
145                display                         = arg.getProparty( "display",display );
146                debug                           = arg.getProparty( "debug"  ,debug );
147
148                // 6.0.2.5 (2014/10/31) TAB を char 化
149                final String sep1 = arg.getProparty( "sep1",null );
150                final String sep2 = arg.getProparty( "sep2",null );
151                if( sep1 != null ) { separator1 = sep1.charAt(0); }
152                if( sep2 != null ) { separator2 = sep2.charAt(0); }
153
154                if( infile1 == null || infile2 == null ) {
155                        final String errMsg = "ファイル名が指定されていません。"
156                                                + "File1=[" + infile1 + "] , File2=[" + infile2 + "]" ;
157                        throw new OgRuntimeException( errMsg );
158                }
159
160                final File file1 = new File( infile1 );
161                final File file2 = new File( infile2 );
162
163                if( ! file1.exists() || ! file2.exists() ) {
164                        // 4.3.1.1 (2008/08/23) Avoid if(x != y) ..; else ..;
165                        final String errMsg = "ファイルが存在しません。"
166                                                + ( file1.exists() ? "" : "File1=[" + file1 + "] " )
167                                                + ( file2.exists() ? "" : "File2=[" + file2 + "]" );
168                        throw new OgRuntimeException( errMsg );
169                }
170
171                if( ! file1.isFile() || ! file2.isFile() ) {
172                        // 4.3.1.1 (2008/08/23) Avoid if(x != y) ..; else ..;
173                        final String errMsg = "フォルダは指定できません。ファイル名を指定してください。"
174                                                + ( file1.isFile() ? "" : "File1=[" + file1 + "] " )
175                                                + ( file2.isFile() ? "" : "File2=[" + file2 + "]" );
176                        throw new OgRuntimeException( errMsg );
177                }
178
179                reader1 = FileUtil.getBufferedReader( file1,encode1 );
180
181                final String[] names ;
182                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
183                final String  clms = arg.getProparty( "columns" );
184                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid if (x != y) ..; else ..;
185                if( clms == null ) {
186                        final String[] clmNames = readName( reader1 );          // ファイルのカラム名配列
187                        if( clmNames == null || clmNames.length == 0 ) { nameNull = true; return ; }
188                        names = clmNames;
189                }
190                else {
191                        names = StringUtil.csv2Array( clms );   // 指定のカラム名配列
192                }
193
194                model = new LineModel();
195                model.init( names );
196
197                if( display ) { println( model.nameLine() ); }
198
199                // 入力カラム名のカラム番号
200                clmNos = new int[names.length];
201                for( int i=0; i<names.length; i++ ) {
202                        clmNos[i] = i+1;                                                // 行番号分を+1しておく。
203                }
204
205                // 比較する列の基準カラム名
206                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
207                final String  keyClms = arg.getProparty( "keyClms" );
208                if( debug ) { println( "DEBUG:\tkeyClms=" + keyClms ); }
209                final String[] keyClmNms = StringUtil.csv2Array( keyClms );
210                keyClmNos = new int[keyClmNms.length];
211                for( int i=0; i<keyClmNms.length; i++ ) {
212                        keyClmNos[i] = model.getColumnNo( keyClmNms[i] );
213        //              if( debug ) { println( "DEBUG:" + keyClmNms[i] + ":[" + keyClmNos[i] + "]" ); }
214        //              int no = model.getColumnNo( keyClmNms[i] );
215        //              if( no >= 0 ) { keyClmNos[no] = i+1; }          // 行番号分を+1しておく。
216                }
217
218                // 比較するカラム名
219                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
220                final String  diffClms = arg.getProparty( "diffClms" );
221                if( debug ) { println( "DEBUG:\tdiffClms=" + diffClms ); }
222                final String[] diffClmNms = StringUtil.csv2Array( diffClms );
223                diffClmNos = new int[diffClmNms.length];
224                for( int i=0; i<diffClmNms.length; i++ ) {
225                        diffClmNos[i] = model.getColumnNo( diffClmNms[i] );
226        //              if( debug ) { println( "DEBUG:" + diffClmNms[i] + ":[" + diffClmNos[i] + "]" ); }
227        //              int no = model.getColumnNo( diffClmNms[i] );
228        //              if( no >= 0 ) { diffClmNos[no] = i+1; }         // 行番号分を+1しておく。
229                }
230
231                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
232                final String  encode2 = arg.getProparty( "encode2",ENCODE );
233                readF2Data( file2,encode2 );
234        }
235
236        /**
237         * プロセスの終了を行います。最後に一度だけ、呼び出されます。
238         * 終了処理(ファイルクローズ、DBクローズ等)に使用します。
239         *
240         * @param   isOK トータルで、OKだったかどうか[true:成功/false:失敗]
241         */
242        public void end( final boolean isOK ) {
243                Closer.ioClose( reader1 );
244                reader1 = null;
245        }
246
247        /**
248         * このデータの処理において、次の処理が出来るかどうかを問い合わせます。
249         * この呼び出し1回毎に、次のデータを取得する準備を行います。
250         *
251         * @og.rev 6.3.1.0 (2015/06/28) nioを使用すると UTF-8とShuft-JISで、エラーになる。
252         * @og.rev 6.5.0.1 (2016/10/21) CharacterCodingException は、OgCharacterException に変換する。
253         *
254         * @return      処理できる:true / 処理できない:false
255         */
256        public boolean next() {
257                if( nameNull ) { return false; }
258
259                boolean flag = false;
260                try {
261                        while((line = reader1.readLine()) != null) {
262                                inCount1++ ;
263                                if( line.isEmpty() || line.charAt(0) == '#' ) { continue; }
264                                else {
265                                        flag = true;
266                                        break;
267                                }
268                        }
269                }
270                // 6.3.1.0 (2015/06/28) nioを使用すると UTF-8とShuft-JISで、エラーになる。
271                catch( final CharacterCodingException ex ) {
272                        final String errMsg = "文字のエンコード・エラーが発生しました。" + CR
273                                                                +       "  ファイルのエンコードが指定のエンコードと異なります。" + CR
274                                                                +       " [" + infile1 + "] , Encode=[" + encode1 + "]" ;
275                        throw new OgCharacterException( errMsg,ex );    // 6.5.0.1 (2016/10/21)
276                }
277                catch( final IOException ex) {
278                        final String errMsg = "ファイル読込みエラー[" + infile1 + "]:(" + inCount1 + ")"  ;
279                        throw new OgRuntimeException( errMsg,ex );
280                }
281                return flag;
282        }
283
284        /**
285         * 最初に、 行データである LineModel を作成します
286         * FirstProcess は、次々と処理をチェインしていく最初の行データを
287         * 作成して、後続の ChainProcess クラスに処理データを渡します。
288         *
289         * ファイルより読み込んだ1行のデータを テーブルモデルに
290         * セットするように分割します
291         * なお、読込みは,NAME項目分を読み込みます。データ件数が少ない場合は、
292         * "" をセットしておきます。
293         *
294         * @param       rowNo   処理中の行番号
295         *
296         * @return      処理変換後のLineModel
297         */
298        public LineModel makeLineModel( final int rowNo ) {
299                outCount++ ;
300                final String[] vals = StringUtil.csv2Array( line ,separator1 );         // 6.0.2.5 (2014/10/31) TAB を char 化
301
302                final int len = vals.length;
303                for( int clmNo=0; clmNo<model.size(); clmNo++ ) {
304                        final int no = clmNos[clmNo];
305                        if( len > no ) {
306                                model.setValue( clmNo,vals[no] );
307                        }
308                        else {
309                                // EXCEL が、終端TABを削除してしまうため、少ない場合は埋める。
310                                model.setValue( clmNo,"" );
311                        }
312                }
313                model.setRowNo( rowNo ) ;
314
315        //      if( display ) { println( model.dataLine() ); }          // 5.1.2.0 (2010/01/01) display の条件変更
316
317                return action( model );
318        }
319
320        /**
321         * キーと、DIFF設定値を比較し、action に応じた LineModel を返します。
322         * action には、ONLY,DIFF,INTERSEC が指定できます。
323         *   ONLY      inFile1 のみに存在する行の場合、inFile1 のレコードを返します。
324         *   DIFF      inFile1 と inFile2 に存在し、かつ、DIFF値が異なる、inFile1 のレコードを返します。
325         *   INTERSEC  inFile1 と inFile2 に存在し、かつ、DIFF値も同じ、inFile1 のレコードを返します。
326         * inFile2 側をキャッシュしますので、inFile2 側のデータ量が少ない様に選んでください。
327         *
328         * @og.rev 6.4.3.1 (2016/02/12) PMD refactoring. HashMap → ConcurrentHashMap に置き換え。
329         *
330         * @param       model LineModelオブジェクト
331         *
332         * @return      実行後のLineModel
333         */
334        private LineModel action( final LineModel model ) {
335                LineModel rtn = null;
336                final Object[] obj = model.getValues();
337
338                // キーのカラムを合成します。
339                final StringBuilder keys = new StringBuilder( BUFFER_MIDDLE );
340                for( int i=0; i<keyClmNos.length; i++ ) {
341                        keys.append( obj[keyClmNos[i]] ).append( ',' );                         // 6.0.2.5 (2014/10/31) char を append する。
342                }
343
344                final String data = file2Map.get( keys.toString() );
345        //      if( debug ) { println( "DEBUG:" + keys.toString() + ":" + data ); }
346
347                if( "ONLY".equalsIgnoreCase( actCmnd ) && data == null ) {
348                        if( debug ) { println( "DEBUG:ONLY\t" + keys.toString() ); }
349                        rtn = model;
350                }
351                else {
352                        // DIFF値のカラムを合成します。
353                        final StringBuilder vals = new StringBuilder( BUFFER_MIDDLE );
354                        for( int i=0; i<diffClmNos.length; i++ ) {
355                                vals.append( obj[diffClmNos[i]] ).append( ',' );                // 6.0.2.5 (2014/10/31) char を append する。
356                        }
357
358                        final boolean eq = vals.toString().equals( data );
359
360                        if( "DIFF".equalsIgnoreCase( actCmnd ) && ! eq ) {
361                                if( debug ) { println( "DEBUG:DIFF\t" + keys.toString() + TAB + data + TAB + vals.toString() ); }
362                                rtn = model;
363                        }
364                        else if( "INTERSEC".equalsIgnoreCase( actCmnd ) && eq ) {
365                                if( debug ) { println( "DEBUG:INTERSEC\t" + keys.toString() + TAB + data ); }
366                                rtn = model;
367                        }
368                }
369                if( display && rtn != null ) { println( rtn.dataLine() ); }
370                return rtn;
371        }
372
373        /**
374         * BufferedReader より、#NAME 行の項目名情報を読み取ります。
375         * データカラムより前に、項目名情報を示す "#Name" が存在する仮定で取り込みます。
376         * この行は、ファイルの形式に無関係に、TAB で区切られています。
377         *
378         * @og.rev 6.0.4.0 (2014/11/28) #NAME 行の区切り文字は、指定の区切り文字を優先して利用する。
379         * @og.rev 6.0.4.0 (2014/11/28) #NAME 判定で、桁数不足のエラーが発生する箇所を修正。
380         * @og.rev 6.3.1.0 (2015/06/28) nioを使用すると UTF-8とShuft-JISで、エラーになる。
381         * @og.rev 6.5.0.1 (2016/10/21) CharacterCodingException は、OgCharacterException に変換する。
382         *
383         * @param       reader PrintWriterオブジェクト
384         *
385         * @return      カラム名配列(存在しない場合は、サイズ0の配列)
386         * @og.rtnNotNull
387         */
388        private String[] readName( final BufferedReader reader ) {
389                try {
390                        // 4.0.0 (2005/01/31) line 変数名変更
391                        String line1;
392                        while((line1 = reader.readLine()) != null) {
393                                inCount1++ ;
394                                if( line1.isEmpty() ) { continue; }
395                                if( line1.charAt(0) == '#' ) {
396                                        // 6.0.4.0 (2014/11/28) #NAME 判定で、桁数不足のエラーが発生する箇所を修正。
397                                        if( line1.length() >= 5 && "#NAME".equalsIgnoreCase( line1.substring( 0,5 ) ) ) {
398                                                // 6.0.4.0 (2014/11/28) #NAME 行の区切り文字は、指定の区切り文字を優先して利用する。
399                                                final char sep ;
400                                                if( TAB != separator1 && line1.indexOf( separator1 ) >= 0 ) {
401                                                        sep = separator1;
402                                                }
403                                                else {
404                                                        sep = TAB;
405                                                }
406                                                // 超イレギュラー処理。#NAME をカラム列に入れない(#NAME+区切り文字 の 6文字分、飛ばす)。
407                                                return StringUtil.csv2Array( line1.substring( 6 ) ,sep );
408                                        }
409                                        else  { continue; }
410                                }
411                                else {
412                                        final String errMsg = "#NAME が見つかる前にデータが見つかりました。";
413                                        throw new OgRuntimeException( errMsg );
414                                }
415                        }
416                }
417                // 6.3.1.0 (2015/06/28) nioを使用すると UTF-8とShuft-JISで、エラーになる。
418                catch( final CharacterCodingException ex ) {
419                        final String errMsg = "文字のエンコード・エラーが発生しました。" + CR
420                                                                +       "  ファイルのエンコードが指定のエンコードと異なります。" + CR
421                                                                +       " [" + infile1 + "] , Encode=[" + encode1 + "]" ;
422                        throw new OgCharacterException( errMsg,ex );    // 6.5.0.1 (2016/10/21)
423                }
424                catch( final IOException ex) {
425                        final String errMsg = "ファイル読込みエラー[" + infile1 + "]:(" + inCount1 + ")"  ;
426                        throw new OgRuntimeException( errMsg,ex );
427                }
428                return new String[0];
429        }
430
431        /**
432         * ファイル属性を読取り、キー情報を作成し、内部メモリマップにキャッシュします。
433         * このマップをもとに、inFile1 のデータを逐次読み取って、処理を進めます。
434         *
435         * @og.rev 6.3.1.0 (2015/06/28) nioを使用すると UTF-8とShuft-JISで、エラーになる。
436         * @og.rev 6.5.0.1 (2016/10/21) CharacterCodingException は、OgCharacterException に変換する。
437         *
438         * @param       file2 読取り元のファイル
439         * @param       encode2 ファイルのエンコード
440         */
441        private void readF2Data( final File file2, final String encode2 ) {
442                BufferedReader reader2 = null;
443                try {
444                        if( debug ) { println( "DEBUG:\tFile2="+ file2 + " 初期処理" ); }
445                        reader2 = FileUtil.getBufferedReader( file2,encode2 );
446                        // 4.0.0 (2005/01/31) line 変数名変更
447                        String line1;
448                        final StringBuilder keys = new StringBuilder( BUFFER_MIDDLE );  // 6.1.0.0 (2014/12/26) refactoring
449                        final StringBuilder vals = new StringBuilder( BUFFER_MIDDLE );  // 6.1.0.0 (2014/12/26) refactoring
450                        while((line1 = reader2.readLine()) != null) {
451                                inCount2++ ;
452                                if( line1.isEmpty() || line1.charAt(0) == '#' ) { continue; }
453                                else {
454                                        // 超イレギュラー処理 最初の TAB 以前の文字は無視する。
455                                        final String line2 = line1.substring( line1.indexOf( separator2 )+1 );
456                                        final Object[] obj = StringUtil.csv2Array( line2 , separator2 );                // 6.0.2.5 (2014/10/31) TAB を char 化
457
458                                        // キーのカラムを合成します。
459                                        keys.setLength(0);                                                                                              // 6.1.0.0 (2014/12/26) refactoring
460                                        for( int i=0; i<keyClmNos.length; i++ ) {
461                                                keys.append( obj[keyClmNos[i]] ).append( ',' );                         // 6.0.2.5 (2014/10/31) char を append する。
462                                        }
463
464                                        // DIFF値のカラムを合成します。
465                                        vals.setLength(0);                                                                                              // 6.1.0.0 (2014/12/26) refactoring
466                                        for( int i=0; i<diffClmNos.length; i++ ) {
467                                                vals.append( obj[diffClmNos[i]] ).append( ',' );                        // 6.0.2.5 (2014/10/31) char を append する。
468                                        }
469
470                                        if( debug ) { println( "DEBUG:\t" + keys.toString() + "\t" + vals.toString() ); }
471
472                                        file2Map.put( keys.toString(), vals.toString() );
473                                }
474                        }
475                        if( debug ) { println( "DEBUG:\t======初期処理終了======" ); }
476                }
477                // 6.3.1.0 (2015/06/28) nioを使用すると UTF-8とShuft-JISで、エラーになる。
478                catch( final CharacterCodingException ex ) {
479                        final String errMsg = "文字のエンコード・エラーが発生しました。" + CR
480                                                                +       "  ファイルのエンコードが指定のエンコードと異なります。" + CR
481                                                                +       " [" + file2.getPath() + "] , Encode=[" + encode2 + "]" ;
482                        throw new OgCharacterException( errMsg,ex );    // 6.5.0.1 (2016/10/21)
483                }
484                catch( final IOException ex) {
485                        final String errMsg = "ファイル読込みエラー[" + file2.getPath() + "]:(" + inCount2 + ")"  ;
486                        throw new OgRuntimeException( errMsg,ex );
487                }
488                finally {
489                        Closer.ioClose( reader2 );
490                }
491        }
492
493        /**
494         * プロセスの処理結果のレポート表現を返します。
495         * 処理プログラム名、入力件数、出力件数などの情報です。
496         * この文字列をそのまま、標準出力に出すことで、結果レポートと出来るような
497         * 形式で出してください。
498         *
499         * @return   処理結果のレポート
500         */
501        public String report() {
502                final String report = "[" + getClass().getName() + "]" + CR
503                                + TAB + "Input  File1  : " + infile1    + CR
504                                + TAB + "Input  File2  : " + infile2    + CR
505                                + TAB + "Input  Count1 : " + inCount1   + CR
506                                + TAB + "Input  Count2 : " + inCount2   + CR
507                                + TAB + "Output Count  : " + outCount ;
508
509                return report ;
510        }
511
512        /**
513         * このクラスの使用方法を返します。
514         *
515         * @return      このクラスの使用方法
516         * @og.rtnNotNull
517         */
518        public String usage() {
519                final StringBuilder buf = new StringBuilder( BUFFER_LARGE )
520                        .append( "Process_TableDiffは、ファイルから読み取った内容を、LineModel に設定後、"            ).append( CR )
521                        .append( "下流に渡す、FirstProcess インターフェースの実装クラスです。"                                 ).append( CR )
522                        .append( CR )
523                        .append( "DBTableModel 形式のファイルを読み取って、各行を LineModel にセットして、"             ).append( CR )
524                        .append( "下流(プロセスチェインのデータは上流から下流に渡されます。)に渡します。"         ).append( CR )
525                        .append( CR )
526                        .append( "引数文字列中に空白を含む場合は、ダブルコーテーション(\"\") で括って下さい。"    ).append( CR )
527                        .append( "引数文字列の 『=』の前後には、空白は挟めません。必ず、-key=value の様に"           ).append( CR )
528                        .append( "繋げてください。"                                                                                                                             ).append( CR )
529                        .append( CR ).append( CR )
530                        .append( getArgument().usage() ).append( CR );
531
532                return buf.toString();
533        }
534
535        /**
536         * このクラスは、main メソッドから実行できません。
537         *
538         * @param       args    コマンド引数配列
539         */
540        public static void main( final String[] args ) {
541                LogWriter.log( new Process_TableDiff().usage() );
542        }
543}