外文翻译JavaIO系统

上传人:鲁** 文档编号:499384536 上传时间:2022-08-03 格式:DOC 页数:16 大小:106KB
返回 下载 相关 举报
外文翻译JavaIO系统_第1页
第1页 / 共16页
外文翻译JavaIO系统_第2页
第2页 / 共16页
外文翻译JavaIO系统_第3页
第3页 / 共16页
外文翻译JavaIO系统_第4页
第4页 / 共16页
外文翻译JavaIO系统_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《外文翻译JavaIO系统》由会员分享,可在线阅读,更多相关《外文翻译JavaIO系统(16页珍藏版)》请在金锄头文库上搜索。

1、文档来源为 :从网络收集整理 .word 版本可编辑 .欢迎下载支持 .外文翻译(英文)The Java I/O SystemCreating a good input/output (I/O) system is one of the more difficult tasks for alanguage designer. This is evidenced by the number of different approaches.The challenge seems to be in covering all possibilities. Not only are there diff

2、erent sources and sinks of I/O that you want to communicate with (files, theconsole, network connections, etc.), but you need to talk to them in a wide variety of ways (sequential, random-access, buffered, binary, character, by lines, by words, etc.). The Java library designers attacked this problem

3、 by creating lots of classes. In fact,there are so many classes for Java I/Os system that it can be intimidating at first (ironically, the Java I/O design actually prevents an explosion of classes). There wasalso a significant change in the I/O library after Java i.o, when the original byte-oriented

4、 library was supplemented with char-oriented, Unicode-based I/O classes. The nio classes (for new I/O, a name we llstill be using years from now eventhough they were introduced in JDK 1.4 and so are already old)were added forimproved performance and functionality. Asa result, there are afair number

5、ofclasses to learn before you understand enough of Java s I/O picture that you can use itproperly. In addition, it rathers important tounderstand the evolution of the I/Olibrary, even if your first reaction is Don t bother me with history, just show me howto use it! The problem is that without the h

6、istorical perspective, you will rapidly become confused with some of the classes and when you should and shouldn use t them.Input and outputProgramming language I/O libraries often use the abstraction of astream, which represents any data source or sink as an object capable of producing or receiving

7、 pieces of data. The stream hides the details of what happens to the data inside the actual I/O device.The Java library classes for I/O are divided by input and output, as you can see by looking at the class hierarchy in the JDK documentation. Through inheritance, everything derived from the InputSt

8、ream or Reader classes has basic methods called1文档来源为 :从网络收集整理 .word 版本可编辑 .欢迎下载支持 .read( ) for reading a single byte or an array of bytes. Likewise, everything derived from OutputStream or Writer classes has basic methods called write( ) for writing a single byte or an array of bytes. However, you

9、won tgenerally use these methods; they exist so that other classes can use them these other classes provide a moreuseful interface. Thus, you ll rarely create your stream object by usingclass,singlebut instead will layer multiple objects together to provide your desired functionality (this is the De

10、corator design pattern, as you shall see in this section). The fact that you create more than one object to produce a single stream is the primary reason that Java s I/O library is confusing.It s helpful to categorize the classes by their functionality. In Java l.o, the library designers started by

11、deciding that all classes that had anything to do with input would be inherited from InputStream, and all classes that were associated with output would be inherited from OutputStream.Type of InputStreamInputStream jobs is to represent classes that produce input from different sources.These sources

12、can be:1. An array of bytes.2. A String obj ect.3. A file.4. A pipe, which works like a physical pipe: You put things in at one end and they come out the other.5. A sequence of other streams, so you can collect them together into a single stream.6. Other sources, such as an Internet connection. (Thi

13、s is covered in Thinking inEnterprise Java, available atEach of these has an associated subclass of InputStream. In addition, the FilterInputStream is also a type of InputStream, to provide a base class for decorator classes that attach attribute or useful interfaces to input streams.Types of Output

14、StreamThis category includes the classes that decide where your output will go: an array of bytes (but not a String presumably, you can create one using the array of bytes), a file, or a pipe.2文档来源为 :从网络收集整理 .word 版本可编辑 .欢迎下载支持 .In addition, the FilterOutputStream provides a base class for decorator

15、 classes that attach attributes or useful interfaces to output streams. This is discussed later.Adding attributes and useful interfacesDecorators were introduced in the Generics chapter, on page 717. The Java I/O library requires many different combinations of features, and this is the justification for using the Decorator design pattern.1 The reason for the existence of the filter classes in the Java I/O library is that the abstract filter class is the base class for all the decorators. A decorator must have the same interface as the object it decorates, but the decora

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 工作计划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号