黑马程序员 java IntputStreamRead把字节转为字符过程分析(二)

2014-11-24 11:42:02 · 作者: · 浏览: 14
return read0(); //额,又是假的;继续看
}
private int read0() throws IOException {
synchronized (lock) {
// Return the leftover char, if there is one
if (haveLeftoverChar) {
haveLeftoverChar = false;
return leftoverChar;
}
// Convert more bytessz
char cb[] = new char[2]; //一次读两个字节
int n = read(cb, 0, 2);
switch (n) {
case -1:
return -1;
case 2:
leftoverChar = cb[1];
haveLeftoverChar = true;
// FALL THROUGH
case 1:
return cb[0];
default:
assert false : n;
return -1;
}// end of catch
}// end of synchronized
}
}
明白了是谁真正负责转换了吧,哈哈