Java I/O Stream hierarchy¶
The Java I/O system utilizes the stream abstraction to handle I/O operations, specifically through InputStream and OutputStream (though the source text explicitly references inputStream and inputStream implementations).^[600-developer__java__java-io__bio-nio-aio.md] The architecture of these streams is fundamentally based on the Decorator Design Pattern.^[600-developer__java__java-io__bio-nio-aio.md]
Decorator Design Pattern¶
In this hierarchy, the顶层接口 serves as the base component, and every subclass holds a reference to the same interface^[600-developer__java__java-io__bio-nio-aio.md]. This design allows functionality to be dynamically layered or "decorated" onto a core stream object.
Stream Types¶
The Java I/O hierarchy is primarily categorized into two types of streams based on their functionality^[600-developer__java__java-io__bio-nio-aio.md]:
- Node Streams (節點流): These streams read from or write to a specific source or destination, such as a file. An example provided is
FileInputStream^[600-developer__java__java-io__bio-nio-aio.md]. - Buffered Streams (緩衝流): These are wrapper streams that add a buffer to an existing stream to improve I/O performance. An example provided is
BufferInputStream^[600-developer__java__java-io__bio-nio-aio.md].
Related Concepts¶
- [[Java NIO]]
- Design Patterns
Sources¶
600-developer__java__java-io__bio-nio-aio.md