// COM3336 Operating Systems // Homework 2 part 1 // John Sung // Started: 10/22/1999 // import java.util.*; import java.io.*; // the File abstract class that defines an interface to all of the different // objects within this file system. public abstract class File { ////////////////////////////////////////////////////////////// // Private Data Members // The name of this File private String FileName; ////////////////////////////////////////////////////////////// // methods that everyone will inherit // the default constructor public File(String fileName) { FileName = fileName; } // get the filename public String getFileName() { return FileName; } ////////////////////////////////////////////////////////////// // Abstract methods in which everyone must // implement in each of the "subfiles" // a function to recursively copy a File, with a file // as the parent of the copy. Parent, only useful for coping // directories. public abstract File recursiveCopy(File Parent); // function to find a particular file and print it to an // ostream public void recursiveFindAndPrint(String prefix, String fileName, PrintStream out) { // if the 2 filenames are same, then print // the full path to this file if (getFileName().compareTo(fileName)==0) out.println(prefix + "/" + fileName); } // function to implement the "du ." command. The object that // implements this function sould print itself if it's // a directory to the ostream. public abstract void recursivePrintDirectory(String prefix, PrintStream out); // function to implement the "du -a" command. The object that // implements this function sould print itself to the ostream. public void recursivePrintAll(String prefix, PrintStream out) { // print myself out.println(prefix + "/" +getFileName()); } // function to implement the directory down command, // returns null if something goes wrong. public abstract File changeDirectory(String subDirName, PrintStream err); // function returns the parent, unless it doesn't have a // parent. Used to implement cd .. public abstract File getParent(); // function used to implement the touch command. // it attempts to create a file. Outputs any errors // to err. public abstract void createFile(String newFileName, PrintStream err); // function used to implement the mkdir command. // it attempts to create a directory. Outputs any errors // to err. public abstract void createDir(String newDirName, PrintStream err); // function used to implement rmdir. Outputs error to // the err PrintStream if something goes wrong. public abstract boolean removeDir(String dirName, PrintStream err); // function used to implement rm. Outputs error to // the err PrintStream if something goes wrong. public abstract boolean removeFile(String fileName, PrintStream err); }