how to make virtual disk - oop final project

4
WARNING! For you who like to think ways on your own, I suggest you not to read this guide as I will spoiler lots of stuff here :p Object Oriented Programming Final Project – Virtual Disk Ok, in short this is a guide for you to make the OOP Final Project: Virtual Disk. I have researched about this project and find it not really hard as long as you know what you have to do . In this guide, I’ll tell you what I’ve known about it. But still you have to think about the implementation by yourself. Hope this guide will help you How will the Virtual Disk work? There are three main features that your virtual disk may have: add, remove, and list. To add file, these are the steps: To remove file, these are the steps: And to list the files, simply use your File Allocation Table. How to Zip and Unzip it?

Upload: fiona-angelina

Post on 06-Nov-2014

2.464 views

Category:

Self Improvement


0 download

DESCRIPTION

Guide to make virtual disk for my class' final project.Virtual disk has the same capabilities as the "standard" disk which is able to: - add file - remove file - list the contentI hope this guide will be useful for you completing this final project :)

TRANSCRIPT

Page 1: How to Make Virtual Disk - OOP Final Project

WARNING! For you who like to think ways on your own, I suggest you not to read this guide as I will spoiler lots of stuff here :p

Object Oriented Programming Final Project – Virtual Disk

Ok, in short this is a guide for you to make the OOP Final Project: Virtual Disk. I have researched about this project and find it not really hard as long as you know what you have to do. In this guide, I’ll tell you what I’ve known about it. But still you have to think about the implementation by yourself. Hope this guide will help you

How will the Virtual Disk work?

There are three main features that your virtual disk may have: add, remove, and list.

To add file, these are the steps:

To remove file, these are the steps:

And to list the files, simply use your File Allocation Table.

How to Zip and Unzip it?

You can use the java.util.zip.* to zip and unzip file. Refer to this link to learn how to zip and unzip it: http://java.sun.com/developer/technicalArticles/Programming/compression/

How to convert files into array of bytes and vice versa?

Page 2: How to Make Virtual Disk - OOP Final Project

Use the class FileInputStream to convert files into array of bytes, and class FileOutputStream to convert array of bytes into files. Use the method: read(b[], offset, length) from FileInputStream and write(b[], offset, length).

Refer to this link to learn how to use it: http://www.mkyong.com/java/how-to-convert-array-of-bytes-into-file/ (I haven’t tried the code myself).

How to allocate the bytes into the Virtual Disk?

Since you need to jump from each sector randomly without erasing the previous data, you need to use RandomAccessFile class as your virtual disk. Make use of these methods: seek(), write(), and read() to jump from one sector to the other, add, and remove file from the virtual disk.

Refer to Java Documentation to learn how to implement these methods.

Add file

Remove file

What is the FAT (File Allocation Table)?

FAT keeps track of your files: where all the parts are stored. Interpreting what Mr. Minaldi has said, the FAT is an object with these attributes:

Filename (String)

Page 3: How to Make Virtual Disk - OOP Final Project

Sectors into which your file’s part are stored (ArrayList/LinkedList/Array/etc, feel free to choose). Make sure the order is correct from start to end.

Size (int/long)

Then you make an ArrayList/LinkedList/Array of object FAT. Now you already have all the information you’re needed to add files (identifying whether the sectors has been occupied or not), remove files (keep track all the sectors in order), and listing the files (get the filename and its size then display it onto the screen).

How to start it?

This is my own way of starting the project. You can follow it or not.

1. Forget about the args[] stuff for now. Better work on the algorithm first: converting, compressing, decompressing, converting back, allocating, collecting, etc.

2. Make sure you know how to convert files into bytes, and vice versa. TXT files are easier to keep track. If you have succeeded in converting them into array of bytes, you’ll have no difficulty in converting ZIP files into bytes because it uses an exactly same procedure, vice versa.

3. Make sure you know how to ZIP and UNZIP file. You’ll need to do minor edits from the link I’ve put above.

4. Start with small size virtual disk, for example 100 bytes. Use TXT files at first (roughly 20-30 bytes). Make sure the TXT can be allocated well throughout the virtual disk (the good thing about using TXT file, you can read it using notepad after being distributed into the Virtual Disk). Or maybe, drawing will help you to understand what I mean:

5. After all works well, try to implement the FAT. Make your virtual disk bigger. Try to use another files such as JPG, PNG, and others. Good luck!

Extra Notes

I don’t think Sir Minaldi wants us to use GUI in this project. Make sure you also use the args[] stuff to run the program cause I think he expects us to use it. Work with single files only! No need to also consider folder.