登录

  • 登录
  • 忘记密码?点击找回

注册

  • 获取手机验证码 60
  • 注册

找回密码

  • 获取手机验证码60
  • 找回
毕业论文网 > 外文翻译 > 电子信息类 > 通信工程 > 正文

与SSH网上商城的系统软件设计毕业论文有关的外文翻译资料:

 2021-03-30 08:03  

Input and output
Programming language I/O libraries often use the abstraction of a stream, which represents
any data source or sink as an object capable of producing or receiving 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 InputStream or Reader classes has basic methods called 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 wonrsquo;t generally use these methods; they exist so that other classes can use
them—these other classes provide a more useful interface. Thus, yoursquo;ll rarely create your
stream object by using a single class, but instead will layer multiple objects together to
provide your desired functionality (this is the Decorator 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 Javarsquo;s I/O library is confusing.
Itrsquo;s helpful to categorize the classes by their functionality. In Java l.o, the library designers
started by 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.
656 Thinking in Java Bruce Eckel
As is the practice in this book, I will attempt to provide an overview of the classes, but
a

可将 Java 库的 IO 类分割为输入与输出两个部分,这一点在用 Web 浏览器阅读联机 Java 类文档时便可知道。通过继承,从 InputStream(输入流)衍生的所有类都拥有名为 read()的基本方法,用于读取单个字节或者字节数组。类似地,从 OutputStream 衍生的所有类都拥有基本方法 write(),用于写入单个字节或者字节数组。然而,我们通常不会用到这些方法;它们之所以存在,是因为更复杂的类可以利用它们,以便提供一个更有用的接口。因此,我们很少用单个类创建自己的系统对象。一般情况下,我们都是将多个对象重叠在一起,提供自己期望的功能。我们之所以感到 Java 的流库( Stream Library)异常复杂,正是由于为了创建单独一个结果流,却需要创建多个对象的缘故。很有必要按照功能对类进行分类。库的设计者首先决定与输入有关的所有类都从 InputStream 继承,而与输出有关的所有类都从 OutputStream 继承。类 功能 构建器参数/如何使用ByteArrayInputStream 允许内存中的一个缓冲区作为 InputStream 使用 从中提取字节的缓冲区/作为一个数据源使用。通过将其同一个 FilterInputStream 对象连接,可提供一个有用的接口286StringBufferInputStream 将一个 String 转换成 InputStream 一个 String(字串)。基础实施方案实际采用一个 StringBuffer(字串缓冲)/作为一个数据源使用。通过将其同一个 FilterInputStream 对象连接,可提供一个有用的接口FileInputStream 用于从文件读取信息 代表文件名的一个 String,或者一个 File 或 ileDescriptor 对象/作为一个数据源使用。通过将其同一个 FilterInputStream 对象连接,可提供一个有用的接口PipedInputString 产生为相关的 PipedOutputStream 写的数据。实现了“管道化”的概念PipedOutputStream/作为一个数据源使用。通过将其同一个 FilterInputStream 对象连接,可提供一个有用的接口SequenceInputStream 将两个或更多的 InputStream 对象转换成单个 InputStream 使用 个InputStream 对象或者一个 Enumeration,用于 InputStream 对象的一个容器/作为一个数据源使用。通过将其同一个FilterInputStream 对象连接,可提供一个有用的接口FilterInputStream 对作为破坏器接口使用的类进行抽象;那个破坏器为其他 InputStream 类提供了有用的功能。

1 0 . 1 . 2 O u t p u t S t r e a m 的类型

这一类别包括的类决定了我们的输入往何处去:一个字节数组(但没有 String;假定我们可用字节数组创建一个文件,或者一个“管道”。

除此以外, FilterOutputStream 为“破坏器”类提供了一个基础类,它将属性或者有用的接口同输出流连接起来。这将在以后讨论ByteArrayOutputStream 在内存中创建一个缓冲区。我们发送给流的所有数据都会置入这个缓冲区。 可选缓冲区的初始大小/用于指出数据的目的地。若将其同FilterOutputStream 对象连接到一起,可提供一个有用的接口FileOutputStream 将信息发给一个文件 用一个 String 代表文件名,或选用一个 File 或 FileDescriptor 对象/用于指出数据的目的地。若将其同 FilterOutputStream 对象连接到一起,可提供一个有用的接口PipedOutputStream 我们写给它的任何信息都会自动成为相关的 PipedInputStream 的输出。实现了“管道化”的概念 PipedInputStream/为多线程处理指出自己数据的目的地/将其同FilterOutputStream 对象连接到一起,便可提供一个有用的接口FilterOutputStream 对作为破坏器接口使用的类进行抽象处理;那个破坏器为其他 OutputStream 类提供了有用的功能。

1 0 . 2 增添属性和有用的接口

利用层次化对象动态和透明地添加单个对象的能力的做法叫作“装饰器”( Decorator)方案—— “方案”属于本书第 16 章的主题(注释①)。装饰器方案规定封装于初始化对象中的所有对象都拥有相同的接口,以便利用装饰器的“透明”性质——

您需要先支付 30元 才能查看全部内容!立即支付

企业微信

Copyright © 2010-2022 毕业论文网 站点地图