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.plugin.io; 017 018import java.util.Arrays; 019 020import 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 */ 037public 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 より読み込んだ1行のデータをテーブルモデルにセットするように分割します 043 * なお、読込みは,NAME項目分を読み込みます。データ件数が少ない場合は、 044 * "" をセットしておきます。 045 * 046 * @og.rev 3.5.5.5 (2004/04/23) DBColumn の size と maxlength の 意味を変更 047 * 048 * @param data 1行のデータ 049 * @param clmSize カラムサイズ 050 * 051 * @return 1行のデータ分の配列 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}