A. Flow
Flow, here is the image of the data exchange method. The process runs in memory and avoids data interactions with the outside world during the run. For example, the data from the hard disk, console, pipe and even sockets (the specific point should be the network card on our computer) read into the address space occupied by our process lock. This data exchange process, which we call a stream. The operation on the stream is called the I/O operation.
Two. Decorator mode
Before we introduce I/O operations in Java, let's introduce decorator mode.
Decorator mode is the combination of objects. If we add a new method to a class, and we don't want to modify the class (or the class might have been compiled and cannot be modified), you can use the inheritance method. At a later time, there are new features that can be used again in an inherited manner. This is simple, but over time will cause the number of our subclasses to swell rapidly. This embarrassment can be solved if we use decorator mode.
Decorator Mode illustration
Car is a very simple function can only run, but we let it fly in the sky, swimming in the water, autonomous driving, and even may appear in the future more functions, we can use the decorator mode.
-
- ICar an abstract component role, which can be an interface or a specific class
- Car Specific Component role
- Supercar decorator, with references to abstract artifacts
- Flycar,watercar,aicar specific decorative roles, adding new features to specific artifacts
Create a car that can fly and swim new water (new Flycar new car)
Third, the decorator mode in I/O
Some classes are not represented in the diagram.
Input is an abstract component, and FilterInputStream is a decorator
A preliminary study of I/O flow in Java (i)