Jungleford is like
PushbackInputStream and PushbackReader are two more confusing classes in the Java I / O system. I used to have a lot of understanding of it (s) until a certain day, I saw the jellyfish Java version of the cow ZMS comments and some information. Have benefited. This is a few months ago, and I only think that this is not a good topic when I write a sequential summary. A Hook Java I / O system that allows you to regret is a typical Decorator mode implementation, which is based on InputStream / OutputStream, through inheritance, constantly add new features, such as file streams, buffers, and addiction. Wait. If you are interested in the I / O system design pattern, you can refer to the article on developerWorks: Design mode from Java class library. Java I / O defaults is not buffered, so-called "buffer" is to temporarily put a piece of byte sequence obtained from the stream in an internal byte array called buffer, then you can take this again. The whole block of byte data, only one byte one byte is one byte by one byte, and the efficiency is high. There are two special input streams to achieve buffer features, one is the BufferedInputStream, which is commonly used, is commonly used like reading files.
BufferedInputStream in = New BufferedInputStream (New FileInputStream ("DataFile"); while ((b = in.read ())! = -1) {...} in. Close ();
This is the code segment we almost don't use JDK documentation. When you write, you should think about a bufferedinputstream meaning. The other is how we don't see the PushbackInputStream (its corresponding character stream mode is PushbackReader). In normal state, "stream" means "one-time", that is, it has changed after you have a working operation, such as reading, whether file or socket, a potential read pointer in the process of reading. "The same thing is moving, you can't reposition after reading (of course, randomaccessfile is another situation), if you used to wearate why a field in the RESULTSET in the database operation, you can no longer be a second time. Here may be an explanation. But I have given us the second time I read in PushbackInputStream. Let's first distinguish the concept of "listening" and "interception", "listening" is a copy of the message, the original message does not change to the destination; "Intercept" is first to put the message first "seizure" "Down, don't let it automatically transfer to the target, but first make some processing in forwarding to the target (if it is a background knowledge of network security), I know" listening "is an attack on" confidentiality ", and" interception " Not only is the "confidentiality" or a "integrity" attack). Some friends have a little understanding of this noun. It is a messaging mechanism for Windows. It seems to be a message interceptive means, but I have a WINDOWS programming. // shy; in addition, if you are familiar with servlet, Can find a process mechanism like Filter, play a little trick before each HTTP request / response is forwarded, determine which shields are thrown, which is "interception". Through the above introduction, we may wish to regard the PushbackInputStream as a "intercept" means for input streams, where the most important method is unread: public void unread (int b) throws ioExceptionpublic void unread (Byte [] b) THROWS IOEXCEPTIONPUBLIC Void unread (byte [] b, int off, int LEN) THROWS IOException
We can imagine a buffer in PushbackInputStream (in fact, you can find this protected by this protected by this protected by the source code), when the low-layer flow comes in, you will flow into this buffer, in you The main "There is also a chance to play a trick to it, and then use the unread method" anti-regret ", put the content that has been read in the buffer (generally not changed, of course, you can also change it, then lose" Zhao Zhao "The meaning is because it is not" complete "), then inserted into the stream head, the remaining part of the flow remaining in the next time, plus the part of the buffer" return ". The above three unread methods represent a part of the buffer "return" one byte, one byte array, and a part of one byte array, respectively. PushbackInputStream is the processing of binary flow, and the character flow is PushbackReader. What is the use? If you have learned compilation, it is easy to understand, such as from left to right, "For (int i = 0; i <10; i )", scanning to "for" can be said to be a keyword? No, maybe it is "for1", it is a variable rather than the keyword, know "(" only realized, oh, I can say "see the for keyword", but "(" It is also returned to the input stream because it is necessary to continue scanning. In context-related languages, this compensation mechanism is more needed. Another example, when the HTML document is parsed, I need to "charset" according to its "Meta" tag. " To decide which character set to use, but html is not "charset" but "" started! So you need to buffer the front of the previous section through the PushbackInputStream buffer, etc. All returned, resolved with the specified character set. Reference Java NetWork Programming. By Elliotte R. Harold ZMS brother's post in the jellyfish post. BY ZMS (helplessly, Shuimu Tsinghua is no longer open to the school) JDK 1.4.2 Documentation. By java.sun.com