public PtsFileConverter(GetOpt opts) {
    FileInputStream fin;
    DataInputStream ins = null;
    FileWriter fout = null;
    try {

      String inFileString = opts.getString("infile");
      String[] inFiles = inFileString.split(",");
      fout = new FileWriter(opts.getString("outfile"), false);
      for (int i = 0; i < inFiles.length; i++) {
        fin = new FileInputStream(inFiles[i]);
        ins = new DataInputStream(fin);

        FeatureCategory type;
        if (opts.getString("type").equals("color")) {
          type = FeatureCategory.COLOR;
        } else if (opts.getString("type").equals("shape")) {
          type = FeatureCategory.SHAPE;
        } else {
          type = FeatureCategory.SIZE;
        }

        if (ins != null && fout != null) {
          convertFile(ins, fout, type);
        }
        ins.close();
        fin.close();
      }

    } catch (Exception ex) {
      System.err.println("ERR: " + ex);
      ex.printStackTrace();
    }
  }
Exemple #2
0
 public Command createCommand(String[] args, int index, GlobalOptions gopt, String workDir) {
   RemoveCommand command = new RemoveCommand();
   command.setBuilder(null);
   final String getOptString = command.getOptString();
   GetOpt go = new GetOpt(args, getOptString);
   int ch = -1;
   go.optIndexSet(index);
   boolean usagePrint = false;
   while ((ch = go.getopt()) != go.optEOF) {
     boolean ok = command.setCVSCommand((char) ch, go.optArgGet());
     if (!ok) {
       usagePrint = true;
     }
   }
   if (usagePrint) {
     throw new IllegalArgumentException(getUsage());
   }
   int fileArgsIndex = go.optIndexGet();
   // test if we have been passed any file arguments
   if (fileArgsIndex < args.length) {
     File[] fileArgs = new File[args.length - fileArgsIndex];
     // send the arguments as absolute paths
     if (workDir == null) {
       workDir = System.getProperty("user.dir");
     }
     File workingDir = new File(workDir);
     for (int i = fileArgsIndex; i < args.length; i++) {
       fileArgs[i - fileArgsIndex] = new File(workingDir, args[i]);
     }
     command.setFiles(fileArgs);
   }
   return command;
 }
  public static void main(String[] args) {
    GetOpt opts = new GetOpt();

    opts.addBoolean('h', "help", false, "Show this help screen");
    opts.addString('i', "infile", null, "Input .pts file");
    opts.addString('o', "outfile", null, "Output feature vector file");
    opts.addString('t', "type", "shape", "Type of features to extract: {color, shape}");

    if (!opts.parse(args)) {
      System.err.println("ERR: " + opts.getReason());
      System.exit(1);
    }
    if (opts.getBoolean("help")) {
      opts.doHelp();
      System.exit(1);
    }

    PtsFileConverter pfc = new PtsFileConverter(opts);
  }