The purpose of this assignment is to gain experience working with Java I/O and exception handling.
Congratulations! MIMP has been a huge commercial success. Your next task is to add some additional functionality related to file I/O. Specifically, you will need to:
The first phase of this project is to design a file format that will allow you to store images to disk. Your file format must be text-based, but beyond that, the layout of your files is entirely up to you. Part of your submission for this project will be a short document describing your file format. You should provide enough information in that document for someone else to implement file I/O methods that could read and write your image files.
Once you have decided on a strategy for storing images to disk, you must update your Image class so that it conforms to the following UML diagram:
Each of the methods highlighted in red are new. No existing methods will need to be modified.
Method Details:
Image(InputStream stream) throws ImageFileFormatException
This constructor should attempt to build an Image object by
reading .mim file data from the provided InputStream
. An
ImageFileFormatException
must be raised if the file does not
conform to your file format. Your code should raise an exception if
it encounters missing data, incorrect data, or extra data.
I suggest that you avoid working with the InputStream
directly.
This method will be easier to complete if you use a utility class such
as Scanner
.
Image(String fileName) throws FileNotFoundException,
ImageFileFormatException
Image(File file) throws FileNotFoundException,
ImageFileFormatException
These constructors provide for more convenient Image creation by
handling the problem of opening an appropriate InputStream
. Each
method raises a FileNotFoundException
if the indicated
file cannot be opened, or a ImageFileFormatException
if
the file can be opened, but is not correctly formatted.
printImage(OutputStream stream)
This method should print properly formatted .mim data to the provided
OutputStream
. Note that this method could be used to
print an image to either a file or the terminal, depending on the
OutputStream
that is provided.
saveImage(String fileName) throws FileNotFoundException
saveImage(File file) throws FileNotFoundException
These methods should write .mim data to the indicated file.
These are convenience methods that handle creating an appropriate
OutputStream
from a file name or a File
object
respectively. Each will throw a FileNotFoundException
if the
indicated file cannot be opened for writing. (These methods should
each include a call to printImage
; they should not duplicate the print
logic.)
Notes:
InputStream
and OutputStream
classes
are abstract. We will discuss abstract classes later in the
course. For now, you can think of them as a categories of classes
rather than as specific classes that can be instantiated directly.
Any class in the InputStream
category (any subclass
of InputStream
) may be passed into the first constructor
above. For the second and third constructors, the most appropriate
type of InputStream
to work with with is
a FileInputStream
. You can find more information on all
of these classes in
the java.io
API.
java.nio
. This
library has some advantages over java.io
, but nothing
that would be particularly helpful for this assignment. For the sake
of keeping everyone on the same page, please do not
use java.nio
for this project.
The second part of this project is to make the necessary modifications
to MimpApp.java
so that we can read and write .mim files using the
graphical application. Files should automatically be saved in the
.mim format if they have the .mim file extension.
The file MimpApp.java
is fairly large, complicated, and
hard to read. (Most of the code in that file was automatically
generated by a GUI design tool.) Don't panic! The changes you
need to make are relatively minor. Don't worry if you don't
understand every line of code. Just do the necessary detective work
to figure out what needs to be modified.
The existing implementation of MimpApp.java
presents the same error
messages if there is any kind of error in reading or writing files.
You may stick to that design: you don't need to print different error
messages for missing or corrupted files.
Submit four files through Web-CAT by the project deadline:
ImageFileFormatException.java
Image.java
MimpApp.java
mim_spec.txt
- A text document containing your file
specification. This document should be clearly written, grammatically
correct, and well organized.
Autograding based on correctness/testing: | 50% |
Instructor grading of GUI functionality: | 20% |
Instructor grading of .mim design document: | 10% |
Autograding based on static analysis of style: | 10% |
Instructor grading based on style and readability: | 10% |
You do not need to submit your own unit tests for this project. Your code will be tested against instructor provided unit tests.
Web-CAT will use checkstyle to analyze your code for conformance to the course style guide. I strongly suggest that you to install checkstyle for Eclipse on your own machine so that you can run your own style checks before submission. You can find the checkstyle configuration file that Web-CAT will use on the course supplemental material page.
This portion of your grade will based on stylistic issues that cannot be checked automatically. This includes:
Your grade will also be based on the number of submissions that you make. You may make up to six submissions with no penalty. Your grade will then be reduced by 3% after every six submissions:
Number of submissions | Penalty |
---|---|
1-6 | 0 |
7-12 | -3% |
13-18 | -6% |
... | ... |