Question: 1 . Begin by examining the FileOperation class that has been provided to you in the homework package. The class represents the result of a

1. Begin by examining the FileOperation class that has been provided to you in the homework package. The class represents the result of a file operation, e.g. attempting to copy or delete a file.
a. The Result enumeration indicates whether the operation was a SUCCESS or an ERROR.
b. The message provides a detailed description of the result.
2.Next, examine the FileUtils class that has been provided to you in the homework package.
a. The copyFile(String source, String destination) method will copy a file from the source path to the destination path. The FileOperation that is returned indicates whether the operation succeeded or failed (and why). You may test the method by running the class and using command line arguments to specify the source and destination file paths.
b. The clearDirectory(String path) method will delete all of the files in the specified directory. The FileOperation that is returned indicates whether the operation succeeded or failed (and why). Be extremely careful when testing this method as you do not want to unintentionally delete any directories! If you accidentally delete files from your project, use the git status and git restore commands to restore them.
3. Create a class named FileCopier. Add a main method.
a. Two directories should be specified as command-line arguments. If there are not exactly two command-line arguments, print a usage message, e.g. "Usage: java homework.FileCopier ", and exit with an error code.
b. Use the FileUtils class to make sure that the output directory is cleared.
c. Use the FileUtils class to copy the files from the input directory to the output directory. Print a message just before each file is copied.
d. Read the documentation on the java.io.File class including the listFiles() method. Use it to list the files in the input directory and copy them into the output directory one at a time. If the file is a directory, skip it. Print a message indicating that it was skipped.
e. Print a message at the end indicating how many files were copied, the total bytes copied, and the time that it took to copy them.
f. If any errors occur, print a detailed message and exit with an error code. Do not rethrow the exception.
g. Below is example output:
Clearing directory 'output'.
Copying file 'books.png'...
Copying file 'buttercup.jpg'...
Copying file 'cutie.jpg'...
Skipping directory 'skip_me'...
Copying file 'tacos.jpg'...
Copying file 'words.txt'...
Copied 5 files (14832559 bytes) in 459 milliseconds.
4. Create a new class, CopierThread that copies a single file in a separate thread of execution.
a. The class will need the name of the file to copy as well as the name of the destination directory into which the file should be copied.
b. You will need to implement the copy in the threads run() method. If an exception occurs, save the result in a field and abort the copy.
c. The name of the file should be printed just before it is copied.
d. It should provide accessors for the number of bytes copied, and the result of the copy.
e. Add a main method that creates one CopierThread per file in the input directory and produces the same output as the main method in FileCopier (including if one or more of the threads encounters an error). This main method should keep track of the total time.
f. Below is example output:
Clearing directory 'output'.
Copying file 'books.png'...
Skipping directory 'skip_me'...
Copying file 'buttercup.jpg'...
Copying file 'cutie.jpg'...
Copying file 'tacos.jpg'...
Copying file 'words.txt'...
Copied 5 files (14832559 bytes) in 58 milliseconds.
5.(10% bonus) Create a new class, Counter, that prints a single number in a separate thread.
a. Add a main method that accepts a single command-line argument that specifies the number to count up to. If there is not exactly one command-line argument, print a usage message, e.g. "Usage: java homework.Counter ", and exit with an error code.
b. Create and start one of your Counter threads for each number. For example, if the number is 10, you should create 10 threads with the numbers 1 through 10(inclusive).
c. You must ensure that the numbers print in order. In order to do this, each thread should wait until the previous thread has finished before printing its own number.
d. Test your implementation several times with at least 100 threads. Ensure that the numbers print in the exact correct order each and every time.
e. Below is example output:
1
2
3
4
5
6
7
8
9
10

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 Programming Questions!