Question: Java Program //// BitOutputStream.java : Zoom Pages import java.util.*; import java.nio.charset.Charset; import java.nio.file.*; import java.io.*; public class BitOutputStream { //I found a Stack of Boolean

Java Program ////

Java Program //// BitOutputStream.java : Zoom Pages import java.util.*; import java.nio.charset.Charset; import

java.nio.file.*; import java.io.*; public class BitOutputStream { //I found a Stack of

BitOutputStream.java :

Zoom

Pages

import java.util.*;

import java.nio.charset.Charset;

import java.nio.file.*;

import java.io.*;

public class BitOutputStream

{

//I found a Stack of Boolean values to be a useful data structure

//But this is optional, feel free to use something else

Stack buffer;

OutputStream os;

BitOutputStream(OutputStream file)

{

buffer = new Stack();

os = file;

}

public void WriteBit(char bit)

{

}

public void WriteBit(String bit)

{

}

public void close()

{

}

//This is an optional function to convert the buffer to a Byte and

output it to os

//I found it useful to have

private void OutputByte()

{

}

}

From Homework 5:

import java.util.*;

import java.nio.charset.Charset;

import java.nio.file.*;

import java.io.*;

public class Homework4 {

public static void main(String[] args) {

Path path = Paths.get("example.bin");

try (OutputStream outputStream =

Files.newOutputStream(path,

StandardOpenOption.CREATE,

StandardOpenOption.APPEND);

BufferedOutputStream buffered =

new

BufferedOutputStream(outputStream)) {

BitOutputStream bitOut = new

BitOutputStream(buffered);

bitOut.WriteBit('0');

bitOut.WriteBit('1');

bitOut.WriteBit("101110");

bitOut.WriteBit("110");

bitOut.close();

} catch (IOException e) {

// do something with e

}

}

}

Files to use: BitOutputStream.java Homework5..ava Objective We are going to write a class to output bits to an output stream Start with the template file for BitOutputStream.java You will submit a completed version of this file. You must fill in the WriteBit(char bit), WriteBit(String bit) and close) functions. Fill in the blank functions so that the class buffers up bits and outputs them to a file once 8 bits have been provided. Bits are input as either the character O' or '1 May also be input as a string, such as "0010010". Details Take the character being input and determine if it is a 1 or 0 then save that to some intermediate buffer The first character entered is the most significant bit of the byte For example: bitOutputStream.write('1)- Right now the byte is 1 bitOutputStream.write'O') Now the byte is 10 (2) bitOutputStream.write("01") Now the byte is 1001 (9) bitOutputStream.write("0110") -8 bits have been entered so the number 150 is output to the file (10010110) When the close) method is called, output whatever bits are in the buffer (even if less than 8) Objective We are going to write a class to output bits to an output stream Start with the template file for BitOutputStream.java You will submit a completed version of this file. You must fill in the WriteBit(char bit), WriteBit(String bit) and close0 functions. Fill in the blank functions so that the class buffers up bits and outputs them to a file once 8 bits have been provided. Bits are input as either the character 'O' or '1 May also be input as a string, such as "0010010". Details Take the character being input and determine if it is a 1 or O then save that to some intermediate buffer The first character entered is the most significant bit of the byte For example: bitOutputStream.write'1) Right now the byte is 1 bitOutputStream.write('O') Now the byte is 10 (2) bitOutputStream.write( "01") - Now the byte is 1001 (9) bitOutputStream.write("0110") 8 bits have been entered so the number 150 is output to the file (10010110). When the close0 method is called, output whatever bits are in the buffer (even if less than 8) Files to use: BitOutputStream.java Homework5..ava Objective We are going to write a class to output bits to an output stream Start with the template file for BitOutputStream.java You will submit a completed version of this file. You must fill in the WriteBit(char bit), WriteBit(String bit) and close) functions. Fill in the blank functions so that the class buffers up bits and outputs them to a file once 8 bits have been provided. Bits are input as either the character O' or '1 May also be input as a string, such as "0010010". Details Take the character being input and determine if it is a 1 or 0 then save that to some intermediate buffer The first character entered is the most significant bit of the byte For example: bitOutputStream.write('1)- Right now the byte is 1 bitOutputStream.write'O') Now the byte is 10 (2) bitOutputStream.write("01") Now the byte is 1001 (9) bitOutputStream.write("0110") -8 bits have been entered so the number 150 is output to the file (10010110) When the close) method is called, output whatever bits are in the buffer (even if less than 8) Objective We are going to write a class to output bits to an output stream Start with the template file for BitOutputStream.java You will submit a completed version of this file. You must fill in the WriteBit(char bit), WriteBit(String bit) and close0 functions. Fill in the blank functions so that the class buffers up bits and outputs them to a file once 8 bits have been provided. Bits are input as either the character 'O' or '1 May also be input as a string, such as "0010010". Details Take the character being input and determine if it is a 1 or O then save that to some intermediate buffer The first character entered is the most significant bit of the byte For example: bitOutputStream.write'1) Right now the byte is 1 bitOutputStream.write('O') Now the byte is 10 (2) bitOutputStream.write( "01") - Now the byte is 1001 (9) bitOutputStream.write("0110") 8 bits have been entered so the number 150 is output to the file (10010110). When the close0 method is called, output whatever bits are in the buffer (even if less than 8)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!