📄 zenkakureader.java
字号:
/**
* IgaLib -> String
* Copyright (C) 2001 Tosiki IGA , IgaLib project member
* (http://homepage2.nifty.com/igat/igapyon/index.html)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package jp.ne.nifty.iga.tosiki.string;
import java.io.*;
/**
* 慡妏曄姺傪峴偆Reader僋儔僗偱偡丅<BR>
*
* 偙偺僋儔僗傪棙梡偡傞偲 敿妏偺暥帤楍傪 壜擻側尷傝慡妏偵曄姺偟側偑傜
* 張棟傪恑傔偰偄偒傑偡丅戺壒傕張棟懳徾偲側偭偰偍傝傑偡丅
* 壗偱傕慡妏偵曄姺偟偰偟傑偄偨偄帪側偳偵曋棙側偙偲偱偟傚偆丅
*
* @author Tosiki IGA
*/
public class ZenkakuReader
extends Reader
{
protected static final boolean IS_DEBUG=false;
protected Reader reader=null;
protected boolean isEndOfStream=false;
/**
* 慡妏曄姺僋儔僗偺僐儞僗僩儔僋僞
*
* @param Reader reader 楢寢偡傞尦偺Reader
*/
public ZenkakuReader(Reader reader)
{
this.reader=reader;
}
/**
* 1暥帤Reader偐傜撉傒崬傒傑偡丅
*
* @return int 撉傒崬傫偩暥帤楍
* @throws IOException 壗偐偟傜偺I/O椺奜
*/
public int read()
throws IOException
{
int iRead=reader.read();
if(iRead<0)
{
isEndOfStream=true;
return iRead;
}
int iReturn=ZenkakuTable.checkHankakuKatakana(reader,iRead);
if(iReturn>=0)
{
return iReturn;
}
iReturn=ZenkakuTable.checkHankakuAscii(reader,iRead);
if(iReturn>=0)
{
return iReturn;
}
return iRead;
}
/**
* 暥帤攝楍傪Reader偐傜撉傒崬傒傑偡丅<BR>
* 2001.08.14 慡偔僶僌偭偰偄偨偺偱廋惓偟傑偟偨丅JUnit梡僐乕僪傪婰嵹偟傑偟偨丅<BR>
*
* @param char cbuf[] 撉傒崬傒愭僶僢僼傽
* @param int off 撉傒崬傒愭僶僢僼傽偺僆僼僙僢僩
* @param int len 撉傒崬傒壜擻側嵟戝挿偝
* @return int 撉傒崬傫偩暥帤楍偺挿偝
* @throws IOException 壗偐偟傜偺I/O椺奜
*/
public final int read(char cbuf[], int off, int len)
throws IOException
{
if(isEndOfStream)
{
return -1;
}
int iNumberOfCharacters=0;
int iTill=off+len;
for(int index=off;index<iTill;index++)
{
int iRead=read();
if(iRead<0)
{
isEndOfStream=true;
break;
}
cbuf[index]=(char)iRead;
iNumberOfCharacters++;
}
return iNumberOfCharacters;
}
/**
* Reader傪僋儘乕僘偟傑偡
*
* @throws IOException 壗偐偟傜偺I/O椺奜偺敪惗
*/
public final void close()
throws IOException
{
if(reader!=null)
{
reader.close();
reader=null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -