byte[] data = TAB_DELIMITED_DATA.getBytes();
InputStream is = new ByteArrayInputStream(data);
// parse data
TableReader ctr = new DelimitedTextTableReader();
Table t = null;
try {
t = ctr.readTable(is);
} catch ( DataIOException e ) {
e.printStackTrace();
fail("Data Read Exception");
}
boolean verbose = TestConfig.verbose();
// text-dump
if (verbose) System.out.println("** TAB DELIMITED DATA TEST **");
if (verbose) System.out.println("-- Data Types -------------");
for (int c = 0, idx = -1; c < t.getColumnCount(); ++c) {
String name = t.getColumnType(c).getName();
if ( (idx=name.lastIndexOf('.')) >= 0 )
name = name.substring(idx+1);
assertEquals(t.getColumnType(c), TYPES[c]);
if (verbose) System.out.print(name + "\t");
}
if (verbose) System.out.println();
if (verbose) System.out.println();
if (verbose) System.out.println("-- Table Data -------------");
for (int c = 0; c < t.getColumnCount(); ++c) {
if (verbose) System.out.print(t.getColumnName(c) + "\t");
assertEquals(t.getColumnName(c), HEADERS[c]);
}
if (verbose) System.out.println();
for (int r = 0; r < t.getRowCount(); ++r) {
for (int c = 0; c < t.getColumnCount(); ++c) {
Object o = t.get(r, c);
if (verbose) System.out.print(o + "\t");
assertEquals(TABLE[c][r], o);
}
if (verbose) System.out.println();
}