//File: Handle.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //This file is the pointer class used by various functions to hold //an instance of a specific device, module, file, or pipe. It also contains its //unique identifier and its read/write permissions. import java.io.RandomAccessFile; import java.io.IOException; public class Handle { private Object type; // Direct pointer to Object private int access; // 1 - Read, 2 - Write, 3 - Read/Write private String ThreadID; // Always Lowercase public Handle() { } public Handle(Object newType, int newAccess, String newID) { type = newType; access = newAccess; ThreadID = newID.toLowerCase(); } public Object getType() { return type; } public int getAccess() { return access; } public String getID() { return ThreadID; } public void finalize() { System.out.println("Finalizing: " + ThreadID); if(ThreadID.startsWith("file")) { try { ((RandomAccessFile)type).close(); } catch(IOException ex) { System.out.println("Error closing File: " + ex); } } if(ThreadID.startsWith("pipe")) { ((Pipe)type).close(); } } }