JAVA (BitOutputStream) Implement a class named BitOutputStream

Feb 3rd, 2012
Studypool Tutor
Price: $10 USD

Tutor description

19.17** (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.

Word Count: 228
Showing Page: 1/2
Tester.javaimport;import;/** * Created by e7006722 on 22/09/2014. */public class Tester { public static void main(String[] args) throws IOException { File file = new File("Excercise19_17.dat"); if(!file.exists()) file.createNewFile(); BitOutputStream bos = new BitOutputStream(file); bos.writeBit("0101"); bos.close(); }}BitOutputStream.javaimport;import;import;import;/** * Created by e7006722 on 22/09/2014. */public

Review from student

Studypool Student
" Thanks, good work "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1819 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors