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.plugin.io;
017    
018    import java.util.Arrays;
019    
020    import org.opengion.fukurou.util.StringUtil;
021    
022    /**
023     * 固定長ファイルの読み取りクラスですã?
024     *
025     * NAMEは、å?頭にã€?NAME とすることで自動的にカラãƒ?��に対応付けますã?
026     * 外部から、指定することもå?来ますã?(外部æŒ?®šが優å…?
027     * 固定長での読み取りでは、各行ã?先é?の行番号は、含めなã�?�§下さã�??先é?よりã€?
028     * ãƒ??タを埋めてくださいã€?
029     *
030     * @og.rev 3.5.4.5 (2004/01/23) 新規作æ?
031     * @og.group ファイル入åŠ?
032     *
033     * @version  4.0
034     * @author   Kazuhiko Hasegawa
035     * @since    JDK5.0,
036     */
037    public class TableReader_Fixed extends TableReader_Default {
038            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
039            private static final String VERSION = "4.0.0.0 (2005/08/31)" ;
040    
041            /**
042             * BufferedReader より読み込んだ?‘行ã?ãƒ??タをテーブルモãƒ?ƒ«にセãƒ?ƒˆするようにåˆ?‰²しまã�?
043             * なおã?読込みは?ŒNAMEé ?›®åˆ?‚’読み込みますã?ãƒ??タ件数が少なã�??合ã?ã€?
044             * "" をセãƒ?ƒˆしておきますã?
045             *
046             * @og.rev 3.5.5.5 (2004/04/23) DBColumn の size と maxlength の 意味を変更
047             *
048             * @param       data    ?‘行ã?ãƒ??タ
049             * @param       clmSize カラãƒ?‚µイズ
050             *
051             * @return      ?‘行ã?ãƒ??タåˆ??配å?
052             */
053            @Override
054            protected String[] readData( final String data,final int clmSize ) {
055                    String[] rtnData = new String[ clmSize ];
056                    String encode = getEncode();
057    
058                    byte[] dt = StringUtil.makeByte( data,encode );
059                    int dtSize = dt.length ;
060    
061                    int startPos = 0;
062                    int clmNo    = 0;
063    
064                    for( ; clmNo < clmSize; clmNo++ ) {
065                            int size = dbColumn[clmNo].getTotalSize() ;             // 4.0.0 (2005/01/31) メソãƒ?ƒ‰名変更
066                            int endPos = startPos + size ;
067    
068                            // ãƒ??タ不足の判定ã?
069                            // 残りのカラãƒ??、ゼロストリングをセãƒ?ƒˆしておきますã?
070                            if( dtSize < endPos ) {
071                                    Arrays.fill( rtnData,clmNo,clmSize,"" );
072                                    break;
073                            }
074    
075                            String val = StringUtil.makeString( dt,startPos,size,encode );
076                            val = dbColumn[clmNo].valueSet( val );
077                            if( val == null ) { val = ""; }
078    
079                            rtnData[clmNo] = val;
080                            startPos = endPos;
081                    }
082    
083                    return rtnData;
084            }
085    }