Asymmetries between FilterInputStream and FilterOutputStream


Costructors

FilterInputStream(InputStream) is protected and FilterOutputStream(OutputStream) is `public.

protected FilterInputStream(InputStream in) {
    this.in = in;
}
public FilterOutputStream(OutputStream out) {
    this.out = out;
}

Methods

FilterInputStream#read(b, off, len) performs in.read(b, off, len) and returns the result and FilterOutputStream#write(b, off, len), on the other hand, calls the write(int) method on each byte to output.

public int read(byte b[], int off, int len) throws IOException {
    return in.read(b, off, len);
}
public void write(byte b[], int off, int len) throws IOException {
    if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
        throw new IndexOutOfBoundsException();

    for (int i = 0 ; i < len ; i++) {
       write(b[off + i]);
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s