Presentation is loading. Please wait.

Presentation is loading. Please wait.

Company Input/Output Stream –. Input/Output Stream Data Program Input Stream Output Stream.

Similar presentations


Presentation on theme: "Company Input/Output Stream –. Input/Output Stream Data Program Input Stream Output Stream."— Presentation transcript:

1 Company Logo @ Input/Output Stream –

2 Input/Output Stream Data Program Input Stream Output Stream

3 Byte stream : InputStream, OutputStream Stream that handle binary data known as byte stream Character stream : Reader, Writer Unicode(2 byte) Stream that handles character data known as character streams.

4 Byte Stream Classes

5 Character Stream Classes

6 InputStream / OutputStream Abstract byte input/output stream class int read( ) int read(byte b[ ]) int read(byte b[], int offset, int length) void close() void write( int b) void write(byte b[ ]) void write(byte b[], int offset, int length) void flush() void close()

7 FileInputStream / FileOutputStream Input source and Output destination byte stream class FileInputStream class construct new FileInputStream(String name)throws FileNotFoundException new FileInputStream(File file)throws FileNotFoundException FileOutputStream class New FileOutputStream(String name, boolean append =false) throws FileNotFoundException New FileOutputStream(File file) throws FileNotFoundException

8 Reader/Writer abstract character input/output stream class FileReader/FileWriter : FileInputStream, FileOutputStream int read( ) int read(char ch[ ]) int read(char ch[], int offset, int length) void write( int ch) void write(char ch[ ]) void write(char ch[], int offset, int length) void write(String s) void write(String s, int offset, int len) void close() Void flush()

9

10 Filter Streams There are four filter streams for the four kinds of stream. OutputStream InputStream Writer Reader Filter streams are the second level streams and always en capsulate the an instance of the corresponding streams. Most of the filter streams have further sub classes enhanc ing the functionality of corresponding stream.

11 FilterOutputStream It is second level stream whose destination is another OutputStream. It is simply passes data to the destination stream. It does not add new methods to the OutputStream Clas s. The various sub class of FilterOutputStream enhance th e functionality available from basic OutputStream class. It has a constructor which takes another OutputStream as a parameter. This encapsulate OutputStream is available to the sub c lasses using protected member callled out which is type of OutputStream Sub Classes : DataOutputStream, BufferedOutputStrea m, PrintStream

12 FilterWriter It is second level stream whose destination is another Writer. It is simply passes data to the destination character str eam. It does not add new methods to the Writer Class. There are no sub class of FilterWriter. It has a constructor which takes another Writer as a pa rameter. This encapsulate Writer is available to the sub classes u sing protected member callled out which is type of Writ er

13 FilterInputStream It is second level stream whose source is another Input Stream. It is simply returns the data from the source. It does not add new methods to the InputStream Class. The various sub class of FilterInputStream enhance the functionality available from basic InputStream class. It has a constructor which takes another InputStream a s a parameter. This encapsulate InputStream is available to the sub cl asses using protected member callled out which is type of InputStream Sub Classes : BufferedInputStream, DataInputStream, PushbackInputStream

14 FilterReader It is second level stream whose source is another Read er. It is simply returns the character data from the source. It does not add new methods to the Reader Class. The various sub class of FilterReader enhance the functi onality available from basic Reader class. It has a constructor which takes another Reader as a p arameter. This encapsulate Reader is available to the sub classes using protected member callled out which is type of Re ader Sub Class : PushbackReader

15 BufferedStream There are four kinds of buffered streams correspond ing to the four types of base stream class. BufferedInputStream BufferedOutputStream BufferedWriter BufferedReader

16 BufferedOutputStream There are two constructors BufferedOutputStream(OutputStream out) BufferedOutputStream(OutputStream out,int buffersize) Default size of buffer is 8192 bytes No Additional methods. Invoking the flush() method would also flush the bu ffer to the destination OutputStream.

17 BufferedWriter There are two constructors BufferedWriter(Writer out) BufferedWriter(Writer out,int buffersize) Default size of buffer is 8192 bytes No Additional methods. Invoking the flush() method would also flush the bu ffer to the destination Writer. Normally, writing to the destination writer takes pla ce in chunks of the buffer size.

18 Piped Streams There are two types of pipes. One is Binary pipe and another is character pipe. It is used to have asynchronous data transfer between the consumer of data and the producer of data. The producer of data would write data to the pipe. The consumer of data would read the data from pipe. There are four Kinds of streams to handle I/O to pipe PipedOutputStream PipedInputStream PipedReader PipedWriter

19 PipedOutputStream This class is an OutputStream that implements one half of a pipe and is useful for communication between threads A PipedOutputStream must be connected to a PipedIn putStream, which may be specified when the PipedOu tputStream is created or with the connect() method. Data written to the PipedOutputStream is available for reading on the PipedInputStream. Methods public void connect (PipedInputStream p) throws IOException Constructors public PipedOutputStream() public PipedOutputStream(PipedInputStream pos)

20 PipedInputStream This class is an InputStream that implements one h alf of a pipe and is useful for communication between threads A PipedInputStream must be connected to a PipedOut putStream, which may be specified when the PipedInp utStream is created or with the connect() method. Data read from a PipedInputStream object is received from the PipedOutputStream to which it is connected Methods public void connect (PipedOutputStream p) throws IOExceptio Constructors public PipedInputStream() public PipedInputStream(PipedOutputStream pos)

21 PipedWriter PipedWriter is a character output stream that writes characters to the PipedReader character input strea m to which it is connected. PipedWriter implements one half of a pipe and is usef ul for communication between two threads of an appli cation. A PipedWriter cannot be used until it is connected to a PipedReader object, which may be passed to the Pipe dWriter() constructor, or to the connect() method. PipedWriter inherits most of the methods of its superc lass Writer. Constructors public PipedWriter() public PipedWriter(PipedReader pr)

22 PipedReader PipedReader is a character input stream that reads ch aracters from a PipedWriter character output stream t o which it is connected. PipedReader implements one half of a pipe and is usef ul for communication between two threads of an appli cation. A PipedReader cannot be used until it is connected to a PipedWriter object, which may be passed to the Pipe dReader() constructor or to the connect() method. PipedReader inherits most of the methods of its super class Constructors public PipedReader() public PipedReader(PipedWriter pr)


Download ppt "Company Input/Output Stream –. Input/Output Stream Data Program Input Stream Output Stream."

Similar presentations


Ads by Google