/* * GNTOptions.java * * Created on November 30, 2003, 6:51 PM */ package gnt; import java.io.*; import java.util.*; // can remove this later: import palm.conduit.*; /** * * @author Mike Kirschman */ public class GNTOptions { private int openFile = 0; private int openGraphics = 0xFFFF; private int numRecs = 0; private long optionsRecSize = 0; /** Creates a new instance of GNTOptions */ public GNTOptions() { } public boolean equals(Object o) { if (o == null) return false; GNTOptions opt = (GNTOptions) o; if (this.getOpenFile() != opt.getOpenFile()) return false; if (this.getOpenGraphics() != opt.getOpenGraphics()) return false; if (this.getNumRecs() != getNumRecs()) return false; return true; } public void readData(DataInputStream dataInputStream) throws IOException { setOpenFile(gnt.Util.readUInt16(dataInputStream)); Log.AddEntry("openFileNumber:" + getOpenFile(), Log.NO_ERROR, true); setOpenGraphics(gnt.Util.readUInt16(dataInputStream)); Log.AddEntry("openGraphicsNumber:" + getOpenGraphics(), Log.NO_ERROR, true); setNumRecs(gnt.Util.readUInt16(dataInputStream)); Log.AddEntry("numberOfRecords:" + getNumRecs(), Log.NO_ERROR, true); setOptionsRecSize(gnt.Util.readUInt32(dataInputStream)); Log.AddEntry("optionsRecSize:" + getOptionsRecSize(), Log.NO_ERROR, true); Log.AddEntry("bytes available after options.readData(..):" + dataInputStream.available(), Log.NO_ERROR, true); } public void writeData(DataOutputStream out) throws IOException { gnt.Util.writeUInt16(out, getOpenFile()); gnt.Util.writeUInt16(out, getOpenGraphics()); gnt.Util.writeUInt16(out, getNumRecs()); gnt.Util.writeUInt32(out, getOptionsRecSize()); } public void printRecord(PrintWriter out, String delimiter) throws IOException { out.print("openFileNumber=" + getOpenFile() + delimiter); out.print("openGraphicsNumber=" + getOpenGraphics() + delimiter); out.print("numberOfRecords=" + getNumRecs() + delimiter); out.print("optionsRecordSize=" + getOptionsRecSize() + delimiter); } public void readRecord(String data, String delimiter){ String nameValue; // Break out the individual fields inside this options section of the data // StringTokenizer lineTokenizer = new StringTokenizer(data, delimiter, false); String[] tokens = Util.split(data, delimiter); Log.AddEntry("data: " + data, Log.NO_ERROR, false); Log.AddEntry("delimeter: " + delimiter, Log.NO_ERROR, false); // Cycle through each field in the options // while(lineTokenizer.hasMoreElements()) { for (int i = 0; i < tokens.length; i++) { // nameValue = lineTokenizer.nextToken(); nameValue = tokens[i]; int equalIdx = nameValue.indexOf('='); Log.AddEntry("Read " + nameValue + " from the flat file.", Log.NO_ERROR, true); // call the appropriate method based on the name String name = nameValue.substring(0, equalIdx); if (name.equals("openFileNumber")) setOpenFile(Integer.parseInt(nameValue.substring(equalIdx + 1))); else if (name.equals("openGraphicsNumber")) setOpenGraphics(Integer.parseInt(nameValue.substring(equalIdx + 1))); else if (name.equals("numberOfRecords")) setNumRecs(Integer.parseInt(nameValue.substring(equalIdx + 1))); else if (name.equals("optionsRecordSize")) setOptionsRecSize(Long.parseLong(nameValue.substring(equalIdx + 1))); } } int getOpenFile() { return openFile; } int getOpenGraphics() { return openGraphics; } int getNumRecs() { return numRecs; } long getOptionsRecSize() { return optionsRecSize; } void setOpenFile(int openFile) { this.openFile = openFile; } void setOpenGraphics(int openGraphics) { this.openGraphics = this.openGraphics; } void setNumRecs(int numRecs) { this.numRecs = numRecs; } void setOptionsRecSize(long optionsRecSize) { this.optionsRecSize = optionsRecSize; } }