Lab 1: File Input/Output


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

Pre-Lab (DUE BEFORE LAB - see due date in Canvas)

As part of the pre-lab activity you will see 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 by the Pre-lab Due Date?


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.


.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:

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

Your program should be able to load images with an .msoe extension located in the images folder of the repository.

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

ImageIO Class

You must implement the following private class methods:

You must implement an ImageIO class with the following public class methods:

Based on the file extension of the Path object, each of these methods 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.

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.

In your readMSOE() and readBMSOE() methods you will need to read the width and height of the image, and then create a WritableImage object so that you can write the data read from the file into an object in memory. As you read the pixel values, you will need to use a PixelWriter to store those values in the WritableImage object that you created.

In your writeMSOE() and writeBMSOE() methods you will use a PixelReader to get the pixel values to write to the output file.

Note that the IOImage class contains a method, hexColorToARGB(String color), that returns the argb value of a pixel as a single integer. This can be used by your readMSOE() method before setting the Argb value of the pixels in the PixelWriter. It also contains argbToHexColor(int argb) that returns a six-digit hex color, which you may also find useful.

ImageCopy Class

You must also implement the ImageCopy class that will contain your main program.

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. The program should not crash or display any exceptions.

Just For Fun

Ambitious students may wish to:


This laboratory assignment, developed by Dr. Chris Taylor.

See your professor's instructions for details on submission guidelines and due dates.