Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

undefined Implement a class named BitOutputStream for writing a stream of bits to a file as follows: +BitOutputStream(file: File) // Creates a BitOutputStream to write

image text in transcribed

image text in transcribed

image text in transcribedundefined

Implement a class named BitOutputStream for writing a stream of bits to a file as follows: +BitOutputStream(file: File) // Creates a BitOutputStream to write bits to the file. +writeBit(char bit): void // Writes a bit 'O' or 'l' to the output stream +writeBit(String bitString): void // Writes a string of bits to the output stream +close(): void // This method must be invoked to close the 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 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 a byte is neither empty nor full, the close() method first fills in zeros to make a full 8 bits in the byte, and then closes the stream. Hint: It might help to look at Exercise 5.44, on page 202, as well as Appendix G on Bitwise operations on page 1169 of the text. Write a program that sends the bits 010000100100001001101 to a file called testOutput.dat. One possible approach to this program is the following outline: public class Program2 { public static void main(String[] args) throws Exception { BitOutputStream output = new BitOutputStream(new File("testOutput.dat")); output.writeBit("010000100100001001101"); output.close(); System.out.println("Done"); } public static class BitOutputStream { private FileOutputStream output; // programs statements // Constructor public BitOutputStream(File file) throws IOException { // one statement will do the job } public void writeBit(String bitString) throws IOException { for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions