// COM3336 Operating Systems // Homework 2 part 1 // John Sung // Started: 10/22/1999 // import java.util.*; import java.io.*; import File; // The simple file to signify a simple file. It really doesn't // add much to the abstract File class. public class SimpleFile extends File { // the default constructor public SimpleFile(String fileName) { super(fileName); } ////////////////////////////////////////////////////////////// // Abstract methods from the abstract File class // a function to recursively copy a File, with a file // as the parent of the copy. Just returns the // copy of itself. public File recursiveCopy(File Parent) { return new SimpleFile(getFileName()); } // function to implement the "du ." command. The object that // implements this function sould print itself if it's // a directory to the ostream. public void recursivePrintDirectory(String prefix, PrintStream out) { // don't do anything since, I'm not a directory } // function to implement the directory down command, // returns null if something goes wrong. public File changeDirectory(String subDirName, PrintStream err) { // print some error since this method should // never have been called. err.println("Error changeDirectory() called to a SimpleFile"); // return null to signify an error. return null; } // function returns the parent, unless it doesn't have a // parent. Used to implement cd .. public File getParent() { // print some error since this method should // never have been called. System.out.println("Error getParent() called to a SimpleFile"); // return null to signify an error. return null; } // function used to implement the touch command. // it attempts to create a file. Outputs any errors // to err. public void createFile(String newFileName, PrintStream err) { // print some error since this method should // never have been called. err.println("Error createFile() called to a SimpleFile"); } // function used to implement the mkdir command. // it attempts to create a directory. Outputs any errors // to err. public void createDir(String newDirName, PrintStream err) { // print some error since this method should // never have been called. err.println("Error createDir() called to a SimpleFile"); } // function used to implement rmdir. Outputs error to // the err PrintStream if something goes wrong. public boolean removeDir(String dirName, PrintStream err) { if (dirName.compareTo(getFileName())==0) { err.println("removeDir: " + dirName + " is a file. Not removed."); return false; } return false; } // function used to implement rm. Outputs error to // the err PrintStream if something goes wrong. public boolean removeFile(String fileName, PrintStream err) { // if the name matches then remove myself from the parent. if (fileName.compareTo(getFileName())==0) { return true; } return false; } }