Example #1
0
 /**
  * Splits a row of data from an ASCII file into its individual fields using the defined field
  * separator.
  *
  * @param line a line of data
  * @return an array of objects
  * @throws Exception exception if the type of the file is undefined
  */
 private Object[] splitRow(String line) throws Exception {
   String[] fields;
   Object[] objects;
   if (type == TYPE_COMMA_SEPERATED) {
     fields = line.split(fieldSeperator, -1);
     objects = new Object[fields.length];
     if (removeQuotes) {
       for (int i = 0; i < fields.length; i++) {
         if (fields[i].startsWith("\"") && fields[i].endsWith("\"")) ;
         {
           objects[i] = fields[i].substring(1, fields[i].length() - 1);
         }
       }
     } else {
       for (int i = 0; i < fields.length; i++) {
         objects[i] = fields[i];
       }
     }
   } else if (type == TYPE_FIXED_LENGTH) {
     fields = new String[parser.getFields().size()];
     objects = new Object[fields.length];
     for (int i = 0; i < parser.getFields().size(); i++) {
       Field field = (Field) parser.getFields().get(i);
       String fieldValue = line.substring(field.getStart(), field.getStart() + field.getLength());
       if (trimFields) {
         objects[i] = fieldValue.trim();
       } else {
         objects[i] = fieldValue;
       }
     }
   } else {
     throw new Exception("undefined row type");
   }
   return objects;
 }
Example #2
0
 /**
  * the layout of a fixed length ASCII row, can be defined in an external XML file. pass the name
  * of the file to this method. the XML file will be parsed, so that the layout can be used.
  *
  * @param fileName the name of the row definition file
  * @throws Exception exception when the file was not found or can not be read
  */
 public void setRowDefinitionFile(String fileName) throws Exception {
   parser = new RowDefinitionParser();
   parser.parse(fileName);
 }