Structured Files due Wed 03 May 11:00

This assignment provides an opportunity to explore the concept ...
...efficiency concerns, disk usage, and continued practice with git.

Existing Program

You will need to pull the latest code from the original homework repository to add the hw07 directory and its files to your homework repository (git pull origin if you are working from the original instructions). The provided code presents a simple program that allows a user to search, view, add, remove, and update books. Each book is represented as a Book object having a title, author, and year. When the program starts, book data is read from a text file. When the program ends, the book data is written back to the text file.

You will write two new versions of this assignment. Begin by creating subdirectories in hw07 called serialize and randomaccess. Make copies of the original provided files in each new directory. Then add the files to the repository and commit with an appropriate message.

Serializing Objects

Your work for this version of the program will go in the serialize directory.

In this first version of the program you will store the book data in a binary file using Java's built-in serializing capabilities. This is accomplished by implementing the Serializable interface for the Book class and then using the ObjectInputStream and ObjectOutputStream I/O classes.

To convert the data you should first modify the saveBooks method to save the serialized objects under the name booklist.ser. After running the program and verifying that the file was created, you can modify the loadBooks method to read the serialized datafile instead of booklist.txt. Also, you should modify the program so that the data file is re-written immediately after a change is made in memory.

Fixed-Length Records

Your work for this version of the program will go in the randomaccess directory.

In this second version of the program you will store the book data in a binary, random access file. As with the first version your program should save changes to disk immediately after they are made in memory. However, rather than re-writing the entire file each time, you should keep the file open throughout the program and use the seek() command to update only that portion of the file that needs to be saved. Thus, your file variable will need to be a class-wide variable and the file will need to be opened in ``rw'' mode.

This version will be built on the RandomAccessFile I/O class. You should assume that no title has more than 64 characters and that no author has more than 32 characters. Save this version of your solution in a repository named randomaccess.


Your work should be posted to your OS homework repository on BitBucket. Your program will be graded based on what you have posted to the server by the due date.

In addition to the two versions of the program your repository should include a text file named compare.txt that compares the three approaches (text file, serialized file, random-access file) in terms of file size.

I will grade you work according the following criteria:

Correctness of serialize 14 pts
Correctness of randomaccess 14 pts
Documentation 2 pts
Java Programming Conventions 2 pts
Use of VCS 2 pts
Contents of compare.txt 4 pts
Total 38 pts

Quick Links