Question: Write a Java program to format an arbitrary text file to have exactly 8 0 Write a Java program to characters per line ( except
Write a Java program to format an arbitrary text file to have exactly Write a Java program to
characters per line except for the last line which may have or less characters after replacing all occurrences of tabs and two or more consecutive
spaces with a single space. Your program must use three threads running
concurrently. The first thread reads characters from the input file using the
provided class AReader, and replaces endofline characters with spaces.
The second thread removes and replaces tabs and removes consecutive
occurrences of spaces, and the third thread writes lines of characters
to the output file using the provided class AWriter. The threads must
communicate characters via circular buffers of length characters using
the algorithm from question The three threads should be started by the main thread of your Java
program. Your program should use cooperative multitasking, ie a thread
should allow others to proceed when it can do no useful work but not
otherwise, and it should terminate gracefully, ie all threads should
reach the end of their run methods.The three threads should be started by the main thread of your Java
program. Your program should use cooperative multitasking, ie a thread
should allow others to proceed when it can do no useful work but not
otherwise, and it should terminate gracefully, ie all threads should
reach the end of their run methods.A zip file containing a file FileConverter.java with your
main method for the program, along with all supporting source java files
apart from AReader and AWriter and a file readme.txt describing in
a few paragraphs the approach you have taken to coding your program.For testing purposes, it is a requirement that you use the
provided AReader and AWriter classes. It is also important that you do
not modify the provided classes. Also, do not make your submitted files
dependent on being in a particular package. That is remove any lines.You should NOT use locks, semaphores, or the synchronized or waitnotify capabilities of Java objects in this Assignment.Please do not make your submitted files dependent on being in a particular package.
This assignment can be implemented just depending on java.io package.
Please ensure any other packages are not imported.
import java.ioBufferedReader;
import java.ioFileReader;
import java.iolOException;
DO NOT MODIFY THIS CLASS
This class is used to read single characters from a file whose name is passed
as a parameter to its constructor.
public class AReader
private BufferedReader br; an object for reading characters from a byte stream
Construct a file reader for reading from a specified file.
@param fileName the name of the file
public AReaderString fileName throws IOException
br new BufferedReadernew FileReaderfileName;
Read a single character from the file.
@return the character or if endoffile is reached is also returned if
an IOException is caught
public int read
try
int i brread;
ignore rcarriage return which occurs before
new line on Windows operating systems
if char i r
i brread;
return i;
catch IOException e
System.err.printlnException occurred while reading.";
return ;
Close the file reader. This should be done when reading to the file is
finished to release associated system resources.
public void close
try
brclose;
catch IOException e
System.err.printInException occurred while closing reader.";
import java.ioFile;
import java.ioFileOutputStream;
import java.ioIOException;
import java.ioPrintWriter;
DO NOT MODIFY THIS CLASS
This class is used to write single characters and line breaks to a file whose
name is passed as a parameter to its constructor.
public class AWriter
PrintWriter pw; an object for writing characters to a byte stream
Construct a file writer for writing to a specified file.
@param fileName the name of the file
public AWriterString fileName throws IOException
pw new PrintWriternew FileOutputStreamnew FilefileName;
Write a single character to the file.
@param d the character
public void writechar d
pwwrited;
Write a line break to the file.
public void lineBreak
pwwriteSystemgetPropertylineseparator";
Close the file writer. This must be done when writing to the file is
finished to ensure any buffered characters are flushed.
public void close
pwclose;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
