Lab 1: File Input/Output

Overview

In this assignment, you will read and write images in two custom formats.

Lab Explanation

Commit 1 - Rename package

Due end of day Tuesday Week 1 (first day of class)

In order to complete commit 1, you will will learn how to use GitHub Classroom to start your lab assignment and submit it when you are finished. When watching the video below, consider the following.

  • How to start a new project from your GitHub repository
  • How to commit changes to your local repo
  • How to push changes from your local repo to GitHub

The project is cloned from the GitHub repo to your local machine at the three minute mark in the video. You will likely need to authorize IntelliJ to access your GitHub account. Hopefully the process is simple enough, but you can see screenshots for what to do in Figures 13-16 of this page.

What Must Be Done for Commit 1?

Commit 2 - ImageIO method stubs

Due end of class Wednesday Week 1

Here you will need to create method stubs for the ImageIO class.

ImageIO Class

The class has the following private class methods:

The ImageIO class has the following public class methods:

The Image reference type is supplied in the mocked package. When creating the stubs, you should import mocked.Image so that the Image references in your method stubs are using mocked.Image.

Commit 3 - ImageCopy implementation

End of class Wednesday Week 1

Your program must accept the name of the input image file and the name of the output image file. The file extention determines whether you should read/write the file in text or binary format. The program should read the input file specified by the user and write it to the output file specified by the user.

The ImageCopy class should contain your main() method which will make use of the ImageIO.read() and ImageIO.write() methods to do much of the work. Your program should be able to load images with an .msoe or .bmsoe extension located in the images folder of the repository.

The read() and write() methods will throw an IllegalArgumentException if an invalid file type is specified in the Path passed the methods. Your program does not need to check for a valid file extension (that will be done in ImageIO, but it does need to anticpate that the calls to read() and write() may produce exceptions.

Note: if the file being read in has more data than expected (based on the width and height), it is considered invalid. You can use the available() method from the InputStream class to determine if there is more data available.

Exception Handling

If any problems are encountered with reading the input files or writing the output file, the program should display a useful error message to the console and terminate gracefully. All messages that respond to exceptions must be written to System.err instead of System.out. The program should not crash or display any exceptions.

Commit 4 - ImageIO read() and readMSOE() implemented

End of class Wednesday Week 1

Based on the file extension of the Path object, the public read() method will call the appropriate private method to do the work. If the path specifies an extension other than msoe or bmsoe, the method must throw an IllegalArgumentException.

.msoe Text Image File Format

The custom .msoe file format is a text based file format for storing images. It is designed to be easy to load and save, but results in comparatively large file sizes. The contents of a very small image of a white-on-black + symbol is shown below:

MSOE
3 3
#000000 #FFFFFF #000000
#FFFFFF #FFFFFF #FFFFFF
#000000 #FFFFFF #000000

Your readMSOE() method will need to read this data from a text file and use it to create a mocked.Image object. Note that a mocked.WritableImage is a mocked.Image. To implemented readMSOE(), you'll need to read the width and height from the text file, and then create a WriteableImage object. You will then read each pixel color from the text file and write that data into the WritableImage object in memory.

Notes:

mocked Package

You are provided with a mocked.Image class implementation containing the following methods:

The mocked.PixelReader interface provides one method: int getArgb(int x, int y) which returns the 32-bit integer value of the color of the pixel located at x, y.

You are also provided with a mocked.WritableImage class implementation which extends mocked.Image and contains:

The mocked.PixelWriter interface provides one method: int setArgb(int x, int y, int argb) which sets the 32-bit integer value of the color of the pixel located at x, y.

Commit 5 - ImageIO write and writeMSOE() implemented

End of class Thursday Week 1

Based on the file extension of the Path object, the public write() method will call the appropriate private method to do the work. If the path specifies an extension other than msoe or bmsoe, the method must throw an IllegalArgumentException.

For this commit you will need to implement the write() and writeMSOE() methods that are similar to the read() and readMSOE() methods; however, instead of reading from a file and writing to an object in memory, you must read from an object in memory and write to a file.

Commit 6 - Lab completed

11pm Monday Week 2

This is the final commit for this lab assignment where you will need to complete any remaining parts of the assignment. In particular, you will need to add support for reading and writing .bmsoe images.

.bmsoe Binary Image File Format

The custom .bmsoe file format is a binary based file format for storing images. It is designed to be easy to load and save as well as produce smaller file sizes than the .msoe format.

The file consists of a sequence of integer values representing the width, height, and pixel values for the image. Each pixel is stored as a single ARGB integer value representing the alpha, red, green, and blue components of the pixel. The pixel values are written from right to left by row - the same order used by .msoe.

Note:

Just For Fun

Ambitious students may wish to:

Acknowledgement

This laboratory assignment, developed by Dr. Chris Taylor.