package cquest.utils; import java.io.*; import java.util.Hashtable; import java.util.Vector; import java.util.Enumeration; /** class InputReader. * class to read parameter from a program from a stream * (stdin or a file). * * the input format is : * -- help * -- end * -- key = value * -- # comments * * @author Michael Sdika */ public class InputReader { /** constructor * @param */ public InputReader() { table = new Hashtable(); } /** add a new key. * the key must not contains =. * */ public void addKey(String key, Callback cb) throws Exception { if (key.indexOf('=')!=-1) { throw new Exception("The key ("+key+") must not contains '='."); } if (key.charAt(0)=='#') { throw new Exception("The key ("+key+") must not begin with '#'."); } if (key.equals(help) || key.equals(run) || key.equals(quit) ) { throw new Exception("The key must be different from "+help+", "+quit+" and "+run+"."); } if (table.containsKey(key)) { throw new Exception("The key "+key+" is already in the table."); } table.put(key,cb); } /** clear the object. */ public void clear() { table.clear(); } /** behaviour of the read function in case of failure. */ public void setRetryIfFail(boolean on) { retryIfFail = on; } /** read. * @return true if run, false if quit. * */ public boolean read(BufferedReader reader, int nbVox) throws IOException { do { // read next line String line; do { line = reader.readLine(); if(line!=null && line.length()>0 ){ if(line.contains("Pixel")) { for (int k=0;k