@Override public TableReader getReader() throws IOException { return new FileTableReader(path, delim, nColumns); }
@Override public String[] getRow() { if (curColumns == null) { if (ReadableTable.DELIM_AUTO.equals(delim)) delim = autoDetectDelim(curLine); if (delim == null) curColumns = new String[] { curLine }; else curColumns = split(curLine, delim); } return curColumns; }
private String[] split(String line, String delim) { // FIXME CVS line should be parsed considering escapes String str[] = StringSplitter.split(line, delim); // un-escape CSV if (ReadableTable.DELIM_COMMA.equals(delim)) { for (int i = 0; i < str.length; i++) { str[i] = unescapeCsv(str[i]); } } return str; }
@Test public void testBasicReader() throws IOException { File f = new File("src/test/resources/dict/DW_SITES"); FileTableReader reader = new FileTableReader("file://" + f.getAbsolutePath(), ReadableTable.DELIM_AUTO, 10); while (reader.next()) { assertEquals("[-1, Korea Auction.co.kr, S, 48, 0, 111, 2009-02-11, , DW_OFFPLAT, ]", Arrays.toString(reader.getRow())); break; } reader.close(); } }
public FileTableReader(String filePath, String delim, int expectedColumnNumber) throws IOException { this.filePath = filePath; this.delim = delim; this.expectedColumnNumber = expectedColumnNumber; FileSystem fs = HadoopUtil.getFileSystem(filePath); try { this.reader = new SeqRowReader(HadoopUtil.getCurrentConfiguration(), fs, filePath); } catch (IOException e) { if (isExceptionSayingNotSeqFile(e) == false) throw e; this.reader = new CsvRowReader(fs, filePath); } }
public FileTableReader(String filePath, String delim, int expectedColumnNumber) throws IOException { this.filePath = filePath; this.delim = delim; this.expectedColumnNumber = expectedColumnNumber; FileSystem fs = HadoopUtil.getFileSystem(filePath); try { this.reader = new SeqRowReader(HadoopUtil.getCurrentConfiguration(), fs, filePath); } catch (IOException e) { if (isExceptionSayingNotSeqFile(e) == false) throw e; this.reader = new CsvRowReader(fs, filePath); } }
@Override public TableReader getReader() throws IOException { return new FileTableReader(path, delim, nColumns); }
@Override public String[] getRow() { if (curColumns == null) { if (FileTable.DELIM_AUTO.equals(delim)) delim = autoDetectDelim(curLine); if (delim == null) curColumns = new String[] { curLine }; else curColumns = split(curLine, delim); } return curColumns; }
private String[] split(String line, String delim) { // FIXME CVS line should be parsed considering escapes String str[] = StringSplitter.split(line, delim); // un-escape CSV if (FileTable.DELIM_COMMA.equals(delim)) { for (int i = 0; i < str.length; i++) { str[i] = unescapeCsv(str[i]); } } return str; }