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     */
016    package org.opengion.fukurou.transfer;
017    
018    import java.io.File;
019    import java.io.PrintWriter;
020    
021    import org.opengion.fukurou.db.Transaction;
022    import org.opengion.fukurou.util.FileUtil;
023    import org.opengion.fukurou.util.StringUtil;
024    
025    /**
026     * 伝é?要求に対してのãƒ??タをファイルに書込みしますã?
027     * ä½?�—、書き込まれるãƒ??タにつã�?�¦は、旧伝é?シスãƒ?ƒ の形式と互換性を持たせるためã?
028     * ãƒ??タのå‰?0Byteに空白で埋め、さらに全体で標準では500Byteになるよã�?�«行末にも空白埋めをしますã?
029     * 500byte以外にしたã�??合ã?、書き込みパラメータの第?’引数に整数でæŒ?®šしてくださいã€?
030     *
031     * 書込みするファイル名ã?、実行対象でæŒ?®šしますã?ファイル名ã?絶対パスでæŒ?®šして下さã�??
032     * またã?書込するãƒ?‚­ストファイルのエンコードã?書込パラメーターでæŒ?®šすることができますã?
033     * æŒ?®šしなã�??合ã?UTF-8が適用されますã?
034     *
035     * @og.group 伝é?シスãƒ?ƒ 
036     *
037     * @version  5.0
038     * @author   Hiroki.Nakamura
039     * @since    JDK1.6
040     */
041    public class TransferExec_SAMCB implements TransferExec {
042    
043            // 書込ファイルオブジェクãƒ?
044    //      private File fileWrite = null;                  // 5.5.2.4 (2012/05/16) ローカル変数åŒ?
045    
046            // 書込ファイルのエンコーãƒ?
047    //      private String fileEncode = null;               // 5.5.2.4 (2012/05/16) ローカル変数åŒ?
048    
049            /**
050             * ファイルに書込みしますã?
051             *
052             * @param vals 伝é?ãƒ??タ(配å?)
053             * @param config 伝é?設定オブジェクãƒ?
054             * @param tran トランザクションオブジェクãƒ?
055             *
056             * @og.rev 5.5.3.3 (2012/06/15) close処ç�?
057             * @og.rev 5.8.1.1 (2014/11/14) パラメータで桁数æŒ?®š可能にする
058             */
059            @Override
060            public void execute( final String[] vals, final TransferConfig config, final Transaction tran ) {
061                    File fileWrite = new File( config.getExecObj() );
062                    
063                    String fileEncode = "UTF-8";
064                    // 5.8.1.1 (2014/11/14) fillByte追åŠ?
065                    int fillByte = 500;
066                    String execPrm = config.getExecPrm();
067                    if( execPrm != null && execPrm.length() > 0 ){
068                            String[] obj = StringUtil.csv2Array( execPrm, ' ' );
069                            fileEncode =  obj[0];
070                            if( obj.length > 1 ) {
071                                    fillByte = Integer.parseInt( obj[1] );
072                            }
073                    }
074    
075    //              String fileEncode = config.getExecPrm();
076    //              if( fileEncode == null || fileEncode.length() == 0 ) {
077    //                      fileEncode = "UTF-8";
078    //              }
079    
080                    PrintWriter writer = FileUtil.getPrintWriter( fileWrite,fileEncode );
081                    String line = null;
082                    for( String s : vals ) {
083                            // å‰?0Byteを空白埋め
084                            String preSpace = StringUtil.stringFill( "", 30, fileEncode );
085                            // 全体で500Byteになるよã�?�«後ろに空白埋め
086                            // 500Byte以外もæŒ?®š可能とする
087    //                      line = StringUtil.stringFill( preSpace + s, 500, fileEncode );
088                            line = StringUtil.stringFill( preSpace + s, fillByte, fileEncode );
089                            writer.println( line );
090                    }
091                    writer.close(); // 5.5.3.3 (2012/06/15)
092            }
093    }