本文介绍了空源FilterInputStream中的/ FilterOutputStream中的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写类的工作就像。

看起来

公共FilterReadableByteChannel实现的ReadableByteChannel {    //我应该允许空通道?
    公共FilterReadableByteChannel(最终的ReadableByteChannel通道){
       // ...
    }
}

和我发现,无论和许可证来源。

  *参数的基本输入流中,或LT; code>空< / code>如果
 *该实例是没有基础流被创建。

问:


  1. 对此有任何实际的原因是什么?

  2. 有没有改变底层源创建后的任何可能的情况下?

我知道为什么不呢?可能是一个答案,但我想知道,如果有,为什么原来的API设计这样做的任何理由。


解决方案

Yes. Even if not declared as such, classes Filter*Stream are conceptually abstract classes. IOW, they only exist to be extended. Subclasses could need to provide the in or out parameters after construction (example: lazily; on first real use), and Filter*Stream gives them this flexibility.

The obvious case is when source is initially null. Other cases that come to my mind are: 1. Creating a subclass of Filter*Stream that acts as a selector. IOW, has several underlying streams and methods to switch from one to the other. 2. Creating a subclass of FilterInputStream that concatenates different InputStreams. 3. Creating a subclass of FilterOutputStream that splits output into different OutputStreams.

Yes: generality.

这篇关于空源FilterInputStream中的/ FilterOutputStream中的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 03:38