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    }