FilterInputStream
FilterInputStreamの機能は、「他の入力ストリームをカプセル化し、追加の機能を提供する」ことです。一般的に使用されるサブクラスは、bufferedinputStreamとdatainputStreamです。
BufferedInputStreamの機能は、「入力ストリームのバッファリング関数、およびMark()およびReset()関数」を提供することです。
DatainputStreamは、他の入力ストリームを飾るために使用されます。これにより、「アプリケーションが基礎となる入力ストリームから基本的なJavaデータ型を機械に依存しない方法で読み取ることができます」。アプリケーションは、DataOutputStreamを使用して、DatainputStreamによって読み取られたデータを記述できます。
FilterInputStreamソースコード(JDK1.7.40に基づく):
パッケージjava.io; public class filterinputStreamはinputstreamを拡張します{保護された揮発性inputstream in; protected filterInputStream(inputStream in){this.in = in; } public int read()throws ioexception {return in.read(); } public int read(byte b [])throws ioexception {return read(b、0、b.length); } public int read(byte b []、int off、int len)throws ioexception {return in.read(b、off、len); } public long skip(long n)throws ioexception {return in.skip(n); } public int vayable()throws ioexception {return in.abailable(); } public void close()throws ioexception {in.close(); } public Synchronized void mark(int readlimit){in.mark(readlimit); } public synchronized void reset()throws ioexception {in.reset(); } public boolean marksupported(){return in.marksupported(); }} filteroutputStream
FilterOutputStreamの機能は、「他の出力ストリームをカプセル化し、追加の機能を提供する」ことです。主にBufferedOutputStream、DataOutputStream、PrintStreamが含まれます。
(01)BufferedOutputStreamの関数は、「出力ストリームのバッファリング関数」を提供することです。
(02)DataOutputStreamは、DataOutputStreamおよびDatainputStream入力ストリームを使用して、他の出力ストリームを飾るために使用され、「アプリケーションが基礎となる入力ストリームから基本的なJavaデータ型を機械に依存しない方法で読み書きできるようにします。」
(03)PrintStreamは、他の出力ストリームを飾るために使用されます。他の出力ストリームに機能を追加し、さまざまなデータ値表現を簡単に印刷できるようにします。
filteroutputStreamソースコード(JDK1.7.40に基づく):
パッケージjava.io; public class filteroutputStreamは、outputStreamを拡張します{プロテクションOutputStream Out; public filteroutputStream(outputStream out){this.out = out; } public void write(int b)throws ioexception {out.write(b); } public void write(byte b [])throws ioexception {write(b、0、b.length); } public void write(byte b []、int off、int len)throws ioexception {(off | len |(b.len + off))|(off + len))<0)new indexoutofboundseception(); for(int i = 0; i <len; i ++){write(b [off+i]); }} public void flush()throws ioException {out.flush(); } public void close()throws ioexception {try {flush(); } catch(ioException araidored){} out.close(); }}