Java - Day 6

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Where does input stream receive data from?

- A file - An array - A peripheral device or a socket

Where does output stream write data to?

- A file - An array - A peripheral device or a socket

List some classes of InputStream

- FileInputStream - ObjectInputStream - DataInputStream - BufferedInputStream

List some classes of OutputStream

- FileOutputStream - ObjectOutputStream - DataOutputStream - BufferedOutputStream - Printstream

Describe InputStream class

- InputStream class is an abstract class. It is the super class of all classes representing an input stream of bytes

Character Writer class

- It is an abstract class for writing to character streams. The methods that a subclass must implement are write(char[], int, int), flush(), and close(). Most subclasses will override some of the methods defined here to provide higher efficiency, functionality or both

Describe Java BufferedOutputStream class

- Java BufferedOutputStream class is used for buffering an output stream. It internally uses buffer to store data. It adds more efficiency than to write data directly into a stream. So, it makes the performance fast.

List 2 classes of Character stream

- Java Character streams are used to perform input and output for 16-bit unicode. Though there are many classes related to character streams but the most frequently used classes are, FileReader and FileWriter - FileInputStream and FileOutputStream can also read and write character stream but the preferred methods are FileReader and FileWriter

Describe Java FileInputStream Class

- Java FileInputStream class obtains input bytes from a file. It is used for reading byte-oriented data (streams of raw bytes) such as image data, audio, video etc. You can also read character-stream data. But, for reading streams of characters, it is recommended to use FileReader class

Describe FileWriter Class

- Java FileWriter class is used to write character-oriented data to a file. It is character-oriented class which is used for file handling in java. - Unlike FileOutputStream class, you don't need to convert string into byte array because it provides method to write string directly

Describe FilterInputStream Class

- Java FilterInputStream class implements the InputStream. It contains different sub classes as BufferedInputStream, DataInputStream for providing additional functionality. So it is less used individually

List 2 classes that use Byte streams

- Java byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream

Describe DataInputStream Class

- allows an application to read primitive data from the input stream in a machine-independent way

Character Reader class

- is an abstract class for reading character streams. The only methods that a subclass must implement are read(char[], int, int) and close(). Most subclasses, however, will override some of the methods to provide higher efficiency, additional functionality, or both. - Some of the implementation class are BufferedReader, CharArrayReader, BufferedWriter, InputStreamReader, PipedReader, StringReader

Describe OutputStream class

- is an abstract class. It is the super class of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink(source)

Describe FileOutputStream Class

- is an output stream used for writing data to a file. If you have to write primitive values into a file, use FileOutputStream class. You can write byte-oriented as well as character-oriented data through FileOutputStream class. But, for character-oriented data, it is preferred to use FileWriter than FileOutStream

Describe ByteArrayInputStream Class

- is composed of two words: ByteArray and InputStream. As the name suggests, it can be used to read byte array as input stream. - Java ByteArrayInputStream class contains an internal buffer which is used to read byte array as stream. In this stream, the data is read from a byte array. - The buffer of ByteArrayInputStream automatically grows according to data

Describe BufferedOutputStream Class

- is used for buffering an output stream. It internally uses buffer to store data. It adds more efficiency than to write data directly into a stream. So, it makes the performance fast.

Describe BufferedWriter Class

- is used to provide buffering for Writer instances. It makes the performance fast. It inherits Writer class. The buffering characters are used for providing the efficient writing of single arrays, characters, and strings

Describe FileReader Class

- is used to read data from the file. It returns data in byte format like FileInputStream class. It is character-oriented class which is used for file handling in java.

Describe BufferedInputStream Class

- is used to read information from stream. It internally uses buffer mechanism to make the performance fast. The important points about BufferedInputStream are: 1- When the bytes from the stream are skipped or read, the internal buffer automatically refilled from the contained input stream, many bytes at a time. 2 When a BufferedInputStream is created, an internal buffer array is created.

Describe BufferedReader Class

- is used to read the text from a character-based input stream. It can be used to read data line by line by readLine() method. It makes the performance fast. It inherits Reader class

Describe ByteArrayOutputStream Class

- is used to write common data into multiple files. In this stream, the data is written into a byte array which can be written to multiple streams later. - The ByteArrayOutputStream holds a copy of data and forwards it to multiple streams. - The buffer of ByteArrayOutputStream automatically grows according to data

Why Java uses the concept of stream?

- to make I/O operation fast

List 3 console streams

1) System.out: standard output stream 2) System.in: standard input stream 3) System.err: standard error stream (output will be highlighted in red)

List useful methods of InputStream

1) public abstract int read()throws IOException reads the next byte of data from the input stream. It returns -1 at the end of file. 2) public int available()throws IOException returns an estimate of the number of bytes that can be read from the current input stream. 3) public void close()throws IOException is used to close the current input stream.

List useful methods of OutputStream

1) public void write(int)throws IOException is used to write a int to the current output stream. 2) public void write(byte[])throws IOException is used to write an array of byte to the current output stream. 3) public void flush() throws IOException flushes the current output stream. 4) public void close()throws IOException is used to close the current output stream.

What is a stream?

A stream is a sequence of data. In Java a stream is composed of bytes


Ensembles d'études connexes

Lipscomb Cognitive Psychology Test 2

View Set

Types of life insurance policies flash cards

View Set