COMPILER DESIGN

ADVANCED TOPICS IN COMPILER DESIGN

CODE GENERATION FOR OBJECT ORIENTED LANGUAGES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which of these class is used to read from byte array?
A
InputStream
B
BufferedInputStream
C
ArrayInputStream
D
ByteArrayInputStream
Explanation: 

Detailed explanation-1: -The ByteArrayInputStream 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.

Detailed explanation-2: -Example: ByteArrayInputStream to read data ByteArrayInputStream input = new ByteArrayInputStream(array); Here, the input stream includes all the data from the specified array. To read data from the input stream, we have used the read() method.

Detailed explanation-3: -A ByteArray is an array of bytes. The ByteArrayInputStream reads this Byte array as an input stream, and ByteArrayOutputStream writes data into this Byte array. Both contain an internal buffer to store data and an internal counter to keep track of the next byte to be read or written.

Detailed explanation-4: -FileInputStream class is useful to read data from a file in the form of sequence of bytes. A file’s input bytes are obtained through the Java FileInputStream class. It is used to read byte-oriented data, which includes image, audio, and video data.

There is 1 question to complete.