Spread the love

Class PipedWriter Class in Java

Spread the love

Class PipedWriter Class in Java

PipedWriter is a character output stream that writes characters to the PipedReader character input stream to which it is connected. PipedWriter implements one half of a pipe and is useful for communication between two threads of an application.

The PipedWriter class represents half of a communication pipe; a PipedReader must be
connected to a PipedWriter. When the two halves of a communication pipe are connected, data written to the PipedWriter can be read from the PipedReader. The communication pipe formed by a PipedWriter and a PipedReader should be used to communicate between threads.

If both ends of a pipe are used by the same thread, the thread can hang. The PipedWriter class is the character-based equivalent of the byte-based PipedOutputStream.

A PipedWriter cannot be used until it is connected to a PipedReader object, which may be passed to the PipedWriter() constructor, or to the connect() method.

PipedWriter inherits most of the methods of its superclass- Writer. PipedWriter is the character stream analog of PipedOutputStream.

The class structure of the PipedWriter is given as

public class java.io.PipedWriter extends java.io.Writer{
// Public Constructors
public PipedWriter();
public PipedWriter(PipedReader reader) throws IOException;
// Public Instance Methods 
public void close() throws IOException;//Defines Writer
public void connect (PipedReader reader) throws IOException;
public void flush () throws IOException;// Defines Writer
public void write (char[] cbuf, int off, int len) throws IOException;//Defines Writer
}

The details of the class discussed as :

public PipedWriter();

public PipedWriter() constructor creates a PipedWriter that is not connected to a PipedReader. The created object must be connected to a PipedReader before it can be used.

public PipedWriter(PipedReader sink);

public PipedWriter(PipedReader sink) constructor creates a PipedWriter that sends data to the given PipedReader.

READ  Class InvalidClassException in Java
READ  Class FileOutputStream in Java

Parameter
sink – The PipedReader to connect

public void close();

public void close() method closes the writer and releases the system resources that are associated with it.

public void connect(PipedReader sink);

public void connect(PipedReader sink) method connects this PipedWriter object to the given PipedReader. If this PipedWriter or sink is already connected, an exception is thrown.

Parameter
sink – The PipedReader to connect.

public void flush();

public void flush() method flushes the writer, which tells the connected PipedReader to notify its readers to read any available data.

public void write(char[] cbuf, int off, int len);

public void write(char[] cbuf, int off, int len) method writes len characters of output from the given array, starting at offset off. The method passes the given data to the connected PipedReader.

Parameter
cbuf – An array of characters to write to the stream.
off – An offset into the character array.
len – The number of characters to write.
Apart from these PipedWriter 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)

PipedWriter class also has inherited methods from class- Writer. They are as follows:




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

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