BitOutputStream) Implement a class named BitOutputStream, as shown
in Figure 19.20, for writing bits to an output stream. The writeBit(char
bit) method stores the bit in a byte variable. When you create a
BitOutputStream, the byte is empty. After invoking writeBit(’1′), the
byte becomes 00000001. After invoking writeBit(“0101″), the byte
becomes 00010101. The first three bits are not filled yet. When a byte is full, it
is sent to the output stream. Now the byte is reset to empty. You must close the
stream by invoking the close() method. If the byte is not empty and not full,
the close() method first fills the zeros to make a full 8 bits in the byte, and
then output the byte and close the stream. For a hint, see Exercise 4.46. Write a
test program that sends the bits 010000100100001001101 to the file named
Exercise19_17.dat.
Click here to place an order for a similar paper and have exceptional work done by our team and get A+results
Click here to place an order for a similar paper and have exceptional work done by our team and get A+results
Objectives
CHAPTER 19
■ To discover how I/O is processed in Java (§19.2).
■ To distinguish between text I/O and binary I/O (§19.3).
■ To read and write bytes using FileInputStream and FileOutputStream (§19.4.1).
■ To filter data using base classes FilterInputStream/FilterOutputStream
(§19.4.2).
■ To read and write primitive values and strings using
DataInputStream/DataOutputStream (§19.4.3).
■ To store and restore objects using ObjectOutputStream
and ObjectInputStream, and to understand how objects
are serialized and what kind of objects can be
serialized (§19.6).
■ To implement the Serializable interface to make objects
serializable (§19.6.1).
■ To serialize arrays (§19.6.2).
■ To read and write files using the RandomAccessFile
class (§19.7)
Click here to place an order for a similar paper and have exceptional work done by our team and get A+results
Click here to place an order for a similar paper and have exceptional work done by our team and get A+results