Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simple 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

Simple Java Program

image text in transcribed

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) 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)

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

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions