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    }