请教大侠,一个关于System.in.read()的问题
小弟最近无事随便翻翻Java的代码,发现常用的System.in.read()方法是一个abstract方法,我的疑问时,System.in.read()的实现是如何的。下面是System.java文件中对in的定义:
/**
* The "standard" input stream. This stream is already
* open and ready to supply input data. Typically this stream
* corresponds to keyboard input or another input source specified by
* the host environment or user.
*/
public final static InputStream in = nullInputStream();
......
/**
* The following two methods exist because in, out, and err must be
* initialized to null. The compiler, however, cannot be permitted to
* inline access to them, since they are later set to more sensible values
* by initializeSystemClass().
*/
private static InputStream nullInputStream() throws NullPointerException {
if (currentTimeMillis() > 0)
return null;
throw new NullPointerException();
}
......
/**
* Initialize the system class. Called after thread initialization.
*/
private static void initializeSystemClass() {
props = new Properties();
initProperties(props);
sun.misc.Version.init();
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
setIn0(new BufferedInputStream(fdIn));
setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
// Load the zip library now in order to keep java.util.zip.ZipFile
// from trying to use itself to load this library later.
loadLibrary("zip");
// Currently File.deleteOnExit is built on JVM_Exit, which is a
// separate mechanism from shutdown hooks. Unfortunately in order to
// work properly JVM_Exit implicitly requires that Java signal
// handlers be set up for HUP, TERM, and INT (where available). If
// File.deleteOnExit were implemented in terms of shutdown hooks this
// call to Terminator.setup() could be removed.
Terminator.setup();
// Set the maximum amount of direct memory. This value is controlled
// by the vm option -XX:MaxDirectMemorySize=<size>. This method acts
// as an initializer only if it is called before sun.misc.VM.booted().
sun.misc.VM.maxDirectMemory();
// Subsystems that are invoked during initialization can invoke
// sun.misc.VM.isBooted() in order to avoid doing things that should
// wait until the application class loader has been set up.
sun.misc.VM.booted();
}
我对initializeSystemClass()方法中做的操作看不太明白,主要是不懂in的是哪个类的实例,in.read()是在什么地方实现的。
特此问题向各位大侠请教。
望不吝赐教!