スポンサーサイト
上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。
新しい記事を書く事で広告が消せます。
import java.io.InputStreamReader;
import java.io.IOException;
/**
* ユーティリティ
*/
public class VnUtil
{
private static char[] charBuf = new char[256];
private static String str = "";
public static String readLine(InputStreamReader isr) throws IOException
{
int count = 0;
String ret = null;
while (true) {
int idxCr = str.indexOf('\r');
int idxLf = str.indexOf('\n');
if ((idxCr < 0 && idxLf < 0)
|| (idxCr >= 0 && idxLf < 0 && idxCr == str.length() - 1)) {
// CRもLFも見つからない場合 or CR単独で末尾に見つかった場合
// InputStreamReaderから新たに読み込む
count = isr.read(charBuf, 0, charBuf.length);
// System.out.println("count=" + count);
if (count >= 0) {
// 読み込めた場合
str += new String(charBuf, 0, count);
// そのままループを回す
} else {
// EOFに達している場合
if (str.equals("")) {
ret = null;
} else if (idxCr >= 0) {
ret = str.substring(0, idxCr);
str = "";
} else {
ret = str;
str = "";
}
break;
}
} else if (idxCr >= 0 && idxLf < 0) {
// CRだけ見つかった場合
// ここに来る場合、CRは末尾以外に見つかっている
ret = str.substring(0, idxCr);
str = str.substring(idxCr + 1);
break;
} else if (idxCr < 0 && idxLf >= 0) {
// LFだけ見つかった場合
ret = str.substring(0, idxLf);
str = str.substring(idxLf + 1);
break;
} else {
// CRとLFが両方見つかった場合
if (idxCr + 1 == idxLf) {
// CRLFが見つかった場合
ret = str.substring(0, idxCr);
str = str.substring(idxLf + 1);
break;
} else {
// CRとLFがバラバラに見つかった場合
throw new IOException();
}
}
}
// System.out.println("ret:'"+ret+"'");
// System.out.println("str:'"+str+"'");
return ret;
}
}
tag : Vanargand
tag : Vanargand