org.apache.commons.io.input.TailerListener#au.com.bytecode.opencsv.CSVParser源码实例Demo

下面列出了org.apache.commons.io.input.TailerListener#au.com.bytecode.opencsv.CSVParser 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Quicksql   文件: CsvStreamReader.java

/**
 * Creates a CsvStreamReader with supplied separator and quote char.
 *
 * @param source The file to an underlying CSV source
 * @param separator The delimiter to use for separating entries
 * @param quoteChar The character to use for quoted elements
 * @param escape The character to use for escaping a separator or quote
 * @param line The line number to skip for start reading
 * @param strictQuotes Sets if characters outside the quotes are ignored
 * @param ignoreLeadingWhiteSpace If true, parser should ignore
 *  white space before a quote in a field
 */
private CsvStreamReader(Source source, char separator, char quoteChar,
                        char escape, int line, boolean strictQuotes,
                        boolean ignoreLeadingWhiteSpace) {
  super(new StringReader("")); // dummy call to base constructor
  contentQueue = new ArrayDeque<>();
  TailerListener listener = new CsvContentListener(contentQueue);
  tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY,
      false, true, 4096);
  this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes,
      ignoreLeadingWhiteSpace);
  this.skipLines = line;
  try {
    // wait for tailer to capture data
    Thread.sleep(DEFAULT_MONITOR_DELAY);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
源代码2 项目: calcite   文件: CsvStreamReader.java

/**
 * Creates a CsvStreamReader with supplied separator and quote char.
 *
 * @param source The file to an underlying CSV source
 * @param separator The delimiter to use for separating entries
 * @param quoteChar The character to use for quoted elements
 * @param escape The character to use for escaping a separator or quote
 * @param line The line number to skip for start reading
 * @param strictQuotes Sets if characters outside the quotes are ignored
 * @param ignoreLeadingWhiteSpace If true, parser should ignore
 *  white space before a quote in a field
 */
private CsvStreamReader(Source source, char separator, char quoteChar,
    char escape, int line, boolean strictQuotes,
    boolean ignoreLeadingWhiteSpace) {
  super(new StringReader("")); // dummy call to base constructor
  contentQueue = new ArrayDeque<>();
  TailerListener listener = new CsvContentListener(contentQueue);
  tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY,
      false, true, 4096);
  this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes,
      ignoreLeadingWhiteSpace);
  this.skipLines = line;
  try {
    // wait for tailer to capture data
    Thread.sleep(DEFAULT_MONITOR_DELAY);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
源代码3 项目: AIDR   文件: TWBTranslationServiceImpl.java

@Transactional
private void processResponseDocumentContent(String content, Integer orderId, Integer projectId) throws Exception {
    BufferedReader reader = new BufferedReader(new StringReader(content));
    String line;
    String[] toks;
    CSVParser parser = new CSVParser();
    int counter = 1;
    reader.readLine();  //skip the first line which is a header.
    while ((line = reader.readLine()) != null) {
        counter++;
        line = line.trim();
        if (line.length() <= 0) continue;
        try {
            toks = parser.parseLine(line);

            if (toks.length != 4) {
                throw new RuntimeException("Invalid number of columns in row " + counter);
            }

            updateTranslation(orderId, new Long(toks[0]), toks[1], toks[2], toks[3]);
        } catch (Exception e) {
            logger.error("Invalid line: " + line + " (" + e.getMessage() + ")");
            throw new RuntimeException("Invalid line: " + line + " (" + e.getMessage() + ")");
        }
    }
}
 
源代码4 项目: Quicksql   文件: CsvStreamReader.java

CsvStreamReader(Source source) {
  this(source,
    CSVParser.DEFAULT_SEPARATOR,
    CSVParser.DEFAULT_QUOTE_CHARACTER,
    CSVParser.DEFAULT_ESCAPE_CHARACTER,
    DEFAULT_SKIP_LINES,
    CSVParser.DEFAULT_STRICT_QUOTES,
    CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE);
}
 
源代码5 项目: cognition   文件: CsvLogRecordParser.java

public void parse(Reader fileReader, String fileType, LogRecordCollector collector) throws IOException {
  try (CSVReader csvReader = new CSVReader(
      fileReader,
      config.getDelimiter(),
      CSVParser.DEFAULT_QUOTE_CHARACTER,
      CSVParser.NULL_CHARACTER);) {

    long line = 0;

    String[] headers = csvReader.readNext();
    line++;
    String[] fieldNames = constructFieldNames(headers, fileType, config.isCleanKeysForES());

    String[] record = null;
    while ((record = csvReader.readNext()) != null) {
      if (record.length != headers.length) {
        // unmatched record length
        LOGGER.warn("Unmatched record column count detected at line {} - header: {} record: {}",
            line, headers.length, record.length);
        continue;
      }
      LogRecord logRecord = new LogRecord();
      for (int i = 0; i < fieldNames.length; i++) {
        if (config.isSkipBlankFields() && StringUtils.isBlank(record[i])) {
          // skip
        } else {
          String value = config.isTrimFieldValue() ? StringUtils.trim(record[i]) : record[i];
          logRecord.setValue(fieldNames[i], value);
        }
      }
      collector.emit(logRecord);
    }
  }
}
 
源代码6 项目: calcite   文件: CsvStreamReader.java

CsvStreamReader(Source source) {
  this(source,
      CSVParser.DEFAULT_SEPARATOR,
      CSVParser.DEFAULT_QUOTE_CHARACTER,
      CSVParser.DEFAULT_ESCAPE_CHARACTER,
      DEFAULT_SKIP_LINES,
      CSVParser.DEFAULT_STRICT_QUOTES,
      CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE);
}
 
源代码7 项目: parquet-mr   文件: AvroCSV.java

static CSVParser newParser(CSVProperties props) {
  return new CSVParser(
      props.delimiter.charAt(0), props.quote.charAt(0),
      props.escape.charAt(0),
      false /* strict quotes off: don't ignore unquoted strings */,
      true /* ignore leading white-space */ );
}
 
源代码8 项目: celos   文件: FileFixTableCreator.java

@Override
public FixTable create(TestRun testRun) throws Exception {
    try (CSVReader reader = new CSVReader(getFileReader(testRun), separator, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER)) {
        List<String[]> myEntries = reader.readAll();
        String[] colNames = myEntries.get(0);
        List<String[]> rowData = myEntries.subList(1, myEntries.size());
        return StringArrayFixTableCreator.createFixTable(colNames, rowData);
    }
}
 
源代码9 项目: kite   文件: CSVUtil.java

public static CSVParser newParser(CSVProperties props) {
  return new CSVParser(
      props.delimiter.charAt(0), props.quote.charAt(0),
      props.escape.charAt(0),
      false /* strict quotes off: don't ignore unquoted strings */,
      true /* ignore leading white-space */ );
}
 

public TestFileIterator(String relationName, Reader reader, char separator, char quotechar,
                    int skipLines,
                    boolean hasHeader) throws InputIterationException {
  this(relationName, reader, separator, quotechar, CSVParser.DEFAULT_ESCAPE_CHARACTER, skipLines,
       CSVParser.DEFAULT_STRICT_QUOTES, CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE, hasHeader);
}
 
源代码11 项目: DataVec   文件: InferredSchema.java

public InferredSchema(String pathToCsv, DataType defaultType, char delimiter) {
    this.pathToCsv = pathToCsv;
    this.defaultType = defaultType;
    this.csvParser = new CSVParser(delimiter);
}
 
源代码12 项目: DataVec   文件: InferredSchema.java

public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote) {
    this.pathToCsv = pathToCsv;
    this.defaultType = defaultType;
    this.csvParser = new CSVParser(delimiter, quote);
}
 
源代码13 项目: DataVec   文件: InferredSchema.java

public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote, char escape) {
    this.pathToCsv = pathToCsv;
    this.defaultType = defaultType;
    this.csvParser = new CSVParser(delimiter, quote, escape);
}
 
源代码14 项目: deeplearning4j   文件: InferredSchema.java

public InferredSchema(String pathToCsv, DataType defaultType, char delimiter) {
    this.pathToCsv = pathToCsv;
    this.defaultType = defaultType;
    this.csvParser = new CSVParser(delimiter);
}
 
源代码15 项目: deeplearning4j   文件: InferredSchema.java

public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote) {
    this.pathToCsv = pathToCsv;
    this.defaultType = defaultType;
    this.csvParser = new CSVParser(delimiter, quote);
}
 
源代码16 项目: deeplearning4j   文件: InferredSchema.java

public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote, char escape) {
    this.pathToCsv = pathToCsv;
    this.defaultType = defaultType;
    this.csvParser = new CSVParser(delimiter, quote, escape);
}