Spread the love

Class FilterOutputStream in Java

Spread the love

Class FilterOutputStream in Java

FilterOutputStream is the superclass of all classes that filter output streams. These streams sit on top of an already existing output stream(the underlying output stream) but provide additional functionalities.

Each of the subclasses of FilterOutputStream works by wrapping an existing output stream called the underlying output stream and providing additional functionality. The methods of FilterOutputStream overrides the methods of outputStream with versions that call the corresponding methods of the underlying stream.

The class FilterOutputStream itself overrides all methods of OutputStream with versions that pass all requests to the underlying OutputStream.Subclasses of FilterOutputStream may further override some of these methods as well as provide additional methods and fields.

It must be subclassed to perform some sort of filtering operation and may not be instantiated directly. An instance of one of the subclasses of FilterOutputStream is constructed with another OutputStream object. The methods of a subclass of FilterOutputStream should override some methods in order to extend their behavior or provide some sort of filtering.

The structure of the class FilterOutputStream is given as:

public class java.io.FilterOutputStream extends java.io.OutputStream{
//member element
protected OutputStream out;
//The outputStream out is under consideration.
//constructor
public FilterOutputStream(OutputStream out);
//creates an output stream filter over the specified OutputStream
//methods
public void close() throws IOException;
public void flush() throws IOException;
public void write(byte b[]) throws IOException;
public void write(byte b[],int offSet,int length) throws IOException;
public void write(int b) throws IOException;
}
 

In addition, all methods may throw an IOException if an IO error occurs apart from their regular Exceptions.
The details of the class structure are given as follows:

protected OutputStream out;

protected OutputStream out is the underlying stream that this FilterOutputStream wraps or filters.

public FilterOutputStream(OutputStream out);

public FilterOutputStream(OutputStream out) constructor creates a FilterOutputStream that sends its data to out.
Parameter
out – The output stream to filter.

public void close() throws IOException;

public void close() method calls the close() method of the underlying stream, which releases any system resources associated with this object.

public void flush() throws IOException;

public void flush() method calls the flush() method of the underlying stream, which forces any bytes that may be buffered by this FilterOutputStream to be written to the underlying device.

public void write(byte b[]) throws IOException;

public void write(byte b[]) method writes the bytes contained in the given array. To accomplish this, it calls write(b,0, b.length). Subclasses need override only write(byte[], int, int) for this method to work automatically.
Parameter
b -An array of bytes to write to the stream.

public void write(byte b[],int offSet,int length) throws IOException;

public void write(byte b[],int offSet,int length) method writes len bytes contained in the given array, starting at offset off. It does this by calling write(int) for each element to be written in the array. This is inefficient, so subclasses should override write(byte[], int, int) with a method that efficiently writes a block of data.
This method returns
Parameter
b -An array of bytes to write to the stream.
off-An offset into the byte array.
len -The number of bytes to write.

public void write(int b) throws IOException;

public void write(int b) throws IOException method writes a byte containing the low-order eight bits of the given integer value. The method calls the write(int) method of the underlying stream.
Parameter
b -The value to write.
Apart from these FilterOutputStream class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)
READ  Class FileDescriptor in Java
READ  Class FileDescriptor in Java




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis of instructions,...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Learn Quickly About DevOps Tools in a Fast and Efficient Manner

Introduction to DevOps tools DevOps tools are a collection of...

How to Collaborate between Development and Operations Team Fast and Effectively

Collaborate between Development and Operations Teams are the key...

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis...

EDITOR PICKS


Spread the love