Reading or writing disk files, JAVA Programming

Assignment Help:

For this assignment, you will simulate a file system. You will be neither creating files nor reading or writing disk files. Rather, you will have a simulation of a file system that resides entirely in memory in your computer.

Each file system has a top level or "root" directory. At this level, there may be an unlimited number of files. In addition to files, this top level directory may also have an unlimited number of subdirectories. These subdirectories may also have an unlimited number of files and/or subdirectories. Thus, just like on a real file system, you may have an unlimited number of files and/or directories in each directory. Since directories may contain other directories, you may have directories nested an unlimited number of levels deep.

You are required to write two files: FileSystem.java, and FileException.java. For FileException.java you will extend the class Exception in java.lang (no import needed). Your FileSystem.java source code file must include the following methods:

public class FileSystem {

                private static final String DEFAULT_NAME = "root";

                /**

                 * Constructor, creates a FileSystem instance,

                 * with the root directory given the name

                 * of the single parameter.

                 *

                 * @paramrootDirectory

                 */

                publicFileSystem(String rootDirectory) {

                }

 

                /**

                 * constructor, creates a FileSystem instance,

                 * with the root directory given the default

                 * name DEFAULT_NAME.

                 */

                publicFileSystem() {

                }

                /**

                 * creates a new subdirectory in the current directory with the directory

                 * name given as a parameter. Throws a FileException if a subdirectory

                 * with the same name or a file with the same name already exists in the

                 * current directory.

                 *

                 * @paramdirName

                 * @throws FileException

                 */

                public void makeDirectory(String dirName)

                throwsFileException {

                }

                /**

                 * Changes the current working directory to the directory specified in

                 * thenewDir string. Changes at only one level at a time (up or down)

                 * are supported. If the user specifies the string .., then the current

                 * working directory moves upward one level. If any other string parameter

                 * is given, then the current working directory moves down one level

                 * to the directory specified. If the directory indicated does not

                 * exist, then a FileException is thrown.

                 *

                 * @paramnewDir

                 * @throws FileException

                 */

                public void changeDirectory(String newDir)

                throwsFileException {

                }

                /**

                 * Creates a new file in the current working subdirectory.

                 * If a file or directory already exists with that name,

                 * then a FileException is thrown.

                 *

                 * @paramfName

                 * @param contents

                 * @throws FileException

                 */

                public void createFile(String fName, String contents)

                throwsFileException {

                }

                /**

                 * Returns true if there exists a directory with the

                 * given name in the current working subdirectory.

                 * Otherwise returns false.

                 *

                 * @paramdirName

                 * @return

                 */

                publicbooleandirectoryExists(String dirName) {

                }

                /**

                 * Returns true if there exists a file with the given

                 * name in the current working subdirectory.

                 * Otherwise returns false.

                 *

                 * @paramfName

                 * @return

                 */

                publicbooleanfileExists(String fName) {

                }

                /**

                 * Removes the directory with the given name from the

                 * current working subdirectory, if it exists, and is

                 * empty. Throws a FileException otherwise.

                 *

                 * @paramdirName

                 * @throws FileException

                 */

                public void deleteDirectory(String dirName)

                throwsFileException {

                }

                /**

                 * Deletes the file with the given name from the current

                 * working subdirectory, if it exists, otherwise throws

                 * aFileException.

                 *

                 * @paramfName

                 * @throws FileException

                 */

                public void deleteFile(String fName)

                throwsFileException {

                }

                /**

                 * Prints the directory and file names in the current working

                 * subdirectory. All directories should be printed before

                 * files. Within each group (directories and files)

                 * entries must be in sorted order (dictionary order)

                 */

                public void printDirectoryContents() {

                }

                /**

                 * Prints the entire contents of the file system tree.

                 * For each subdirectory starting with the root or top level

                 * directory, all directories and files are printed. Levels of

                 * nesting should indicated by inserting spaces before the

                 * nested directory or filename. Use 5 blank spaces for each

                 * level of nesting. Entries in a subdirectory must immediately

                 * follow that directory name in the listing.

                 */

                public void printAll() {

                }

 

 

                /**

                 * Returns the content of a file stored in the current

                 * working subdirectory identified by the parameter fName.

                 * Throws a FileException if the file is not found, or it is

                 * a directory instead of a file.

                 *

                 * @paramfName

                 * @return

                 * @throws FileException

                 */

                public String getContents(String fName)

                throwsFileException {

                }

                /**

                 * Returns the String representation of the current working directory.

                 *

                 * @return

                 */

                public String getCurrentDirectory() {

                }

 

 

                /**

                 * Returns the current number of subdirectories and files in the file

                 * system. A FileSystem with only a root directory has size == 0

                * (provided that the root directory is empty).

                 *

                 * @return

                 */

                publicint size() {

                }

The source code has been placed in your CVS accounts.

Additional Details and Requirements

The constructor will create an empty file system with a top level directory, either a name provided or DEFAULT_NAME.

File and directory names consist of a single String object. Any valid string is a valid filename except for the String ".." which indicates the parent subdirectory.

Each new entry in the file system has the following information. 1) name of directory or file, 2) text contents if the entry is a file. Text contents is a single string representing the file contents.

Each subdirectory may contain additional subdirectories and files, with no limit on the number of entries.

Within each directory, all contents should be kept in alphabetical order. All subdirectories must appear first (in dictionary order) followed by all files (in dictionary order).

When printing directories, the directory name should always be followed by a "/".

The printAll() method must be recursive.

You may use any classes that you wrote for program #1.

You may import only java.io.*, data_structures.*, java.util.Iterator, java.util.NoSuchElementException, and java.util.StringTokenizer.

Your project must include the FileSystem class and the FileException class, named appropriately. Additionally, you must implement all of the methods specified in the FileSystem class, and the name and signature of each method must match the specifications.

You may include as many additional classes as you need. Any data structures or ADT's you use must be in a package named data_structures. You must write any data structures or ADT's you need yourself, and they should handle Objects of any type, not just directories and files.

Much of the work in this assignment involves developing a good design. Give careful thought to the organization of directory/file information. The overall quality of your design will be worth approximately 30% of your grade for the assignment.

You will submit a report (maximum 5 pages) along with your source code that describes your design.

None of your public methods may return pointers to private internal objects. In particular, if you use a linked list data structure, you must not return a Node in any public method. Proper use of information hiding and encapsulation are expected.

Be careful about storing extraneous information along with files and directories. Useless replication of data is inappropriate, and will lower your overall grade.

Your project will be graded with a driver program not available to you. The driver program will instantiate instances of the class FileSystem only. Drivers must not reference any other classes in your project.


Related Discussions:- Reading or writing disk files

What are the principle concepts of oops, What are the principle concepts of...

What are the principle concepts of OOPS? Principle concepts upon that object oriented programming and design rest. They are: Abstraction: Abstraction refers to the act of

Java Thread, What is use of join in Java Threading

What is use of join in Java Threading

Url instance and url connection instance, Difference between URL instance a...

Difference between URL instance and URL Connection instance? Ans) A URL instance shows the location of a resource, and a URL Connection instance shows a link for accessing or co

Give an example for using getter methods, Give an example for Using Getter ...

Give an example for Using Getter Methods ? class CarTest6 { public static void main(String args[]) { Car c = new Car(); c.setLicensePlate("New York A45 636"); c.setMa

Why use rmi when we can handle the same benefits from ejb?, EJBs are distri...

EJBs are distributed elements, which need the RMI framework for object distribution. An EJB application server gives more services like object pooling, transaction management, data

Web-based client program, Why are JSP pages the preferred API for creating ...

Why are JSP pages the preferred API for creating a web-based client program? Because no plug-ins or security policy files are required on the client systems (applet does). Also,

Forward action and include action, What is the difference among ForwardActi...

What is the difference among ForwardAction and IncludeAction? Ans) The difference is that you require to use the IncludeAction only if the action is going to be contained by ano

Expertise in gps or navigation app coding, Project Description: Two co-f...

Project Description: Two co-founders are in search of a developer to join us to launch a tech startup. We have experience at fortune 500 companies, elite consulting firms, etc.,

Develop a camera application, Project Description: I want to build a cam...

Project Description: I want to build a camera application for android. By default android will add metadata for the image, for e.g.  Date, time, resolution, gps tag etc..In this

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd