/** * A static convenience method that returns the first line of the * specified file as list of strings, using the specified regexp as * delimiter. * * @param filename the file to read from * @param delim a regexp on which to split lines into fields (default whitespace) */ public static List<String> firstRecord(String filename, String delim) throws FileNotFoundException { RecordIterator it = new RecordIterator(filename, delim); if (!it.hasNext()) return null; return it.next(); }
public List<String> next() { List<String> result = nextResult; advance(); return result; }
/** * A static convenience method that tells you how many fields are in the * first line of the specified file, using the default whitespace * delimiter. * * @param filename the file to read from */ public static int determineNumFields(String filename) throws FileNotFoundException { return determineNumFields(filename, WHITESPACE); }
public static DataSeries[] readDataSeries(InputStream in) { return readDataSeries(new RecordIterator(in), false); }
/** * A static convenience method that returns the first line of the * specified file as list of strings, using the default whitespace * delimiter. * * @param filename the file to read from */ public static List<String> firstRecord(String filename) throws FileNotFoundException { return firstRecord(filename, WHITESPACE); }
public static DataSeries[] readDataSeries(InputStream in, boolean useHeaders) { return readDataSeries(new RecordIterator(in), useHeaders); }
/** * A static convenience method that tells you how many fields are in the * first line of the specified file, using the specified regexp as * delimiter. * * @param filename the file to read from * @param delim a regexp on which to split lines into fields (default whitespace) */ public static int determineNumFields(String filename, String delim) throws FileNotFoundException { List<String> fields = firstRecord(filename, delim); if (fields == null) return -1; else return fields.size(); }
/** * Just for testing. Reads from the file named on the command line, or from * stdin, and echoes the records it reads to stdout. */ public static void main(String[] args) throws FileNotFoundException { RecordIterator it = null; if (args.length > 0) { it = new RecordIterator(args[0]); } else { it = new RecordIterator(System.in); log.info("[Reading from stdin...]"); } while (it != null && it.hasNext()) { List<String> record = it.next(); for (String field : record) { System.out.printf("[%-10s]", field); } System.out.println(); } }
public static DataSeries[] readDataSeries(String filename, boolean useHeaders) throws FileNotFoundException { return readDataSeries(new RecordIterator(filename), useHeaders); }
/** * Returns an <code>Iterator</code> over records (lists of strings) * corresponding to lines in the specified <code>Reader</code>. * * @param reader the reader to read from * @param fields how many fields to expect in each record * @param filter whether to filter lines containing wrong number of fields * @param delim a regexp on which to split lines into fields (default whitespace) */ public RecordIterator(Reader reader, int fields, boolean filter, String delim) { this.reader = new BufferedReader(reader); this.fields = fields; this.filter = filter; this.delim = delim; if (delim == null) this.delim = WHITESPACE; advance(); }
public static DataSeries[] readDataSeries(String filename) throws FileNotFoundException { return readDataSeries(new RecordIterator(filename), false); }