Java 类org.apache.commons.csv.CSVStrategy 实例源码

项目:MyDMAM    文件:FTPActivity.java   
public static void getAllUserActivitiesCSV(String user_session_ref, OutputStream destination) throws Exception {
    if (Elasticsearch.isIndexExists(ES_INDEX) == false) {
        throw new Exception("noindex");
    }

    CSVStrategy strategy = new CSVStrategy(';', '\"', '#', '\\', true, true, true, true);
    final CSVPrinter printer = new CSVPrinter(destination).setStrategy(strategy);

    printer.println(new String[] { "Date", "Session", "User name", "User domain", "User group", "User session ref", "Action", "Working Directory", "Argument", "File size", "File offset",
            "Sec after login", "Client" });

    ElastisearchCrawlerReader ecr = Elasticsearch.createCrawlerReader();
    ecr.setIndices(ES_INDEX);
    ecr.setTypes(ES_TYPE);
    ecr.setQuery(searchByUserSessionRef(user_session_ref));
    ecr.addSort("activity_date", SortOrder.ASC);

    ecr.allReader(new ElastisearchCrawlerHit() {

        public boolean onFoundHit(SearchHit hit) throws Exception {
            printer.println(getCSVLine(hit.getSource()));
            return true;
        }
    });
}
项目:alfresco-remote-api    文件:DeclarativeSpreadsheetWebScript.java   
/**
 * Get the CSVStrategy. Returns {@link CSVStrategy#EXCEL_STRATEGY} if none was set.
 * 
 * @return CSVStrategy
 */
public CSVStrategy getCsvStrategy()
{
    if (csvStrategy == null)
    {
        return CSVStrategy.EXCEL_STRATEGY;
    }
    else
    {
        return csvStrategy;
    }
}
项目:alfresco-remote-api    文件:UserCSVUploadPost.java   
protected void processCSVUpload(InputStream input, List<Map<QName,String>> users)
    throws IOException
{
    InputStreamReader reader = new InputStreamReader(input, Charset.forName("UTF-8"));
    CSVParser csv = new CSVParser(reader, CSVStrategy.EXCEL_STRATEGY);
    String[][] data = csv.getAllValues();
    if(data != null && data.length > 0)
    {
        processSpreadsheetUpload(data, users);
    }
}
项目:community-edition-old    文件:DeclarativeSpreadsheetWebScript.java   
/**
 * Get the CSVStrategy. Returns {@link CSVStrategy#EXCEL_STRATEGY} if none was set.
 * 
 * @return CSVStrategy
 */
public CSVStrategy getCsvStrategy()
{
    if (csvStrategy == null)
    {
        return CSVStrategy.EXCEL_STRATEGY;
    }
    else
    {
        return csvStrategy;
    }
}
项目:community-edition-old    文件:UserCSVUploadPost.java   
protected void processCSVUpload(InputStream input, List<Map<QName,String>> users)
    throws IOException
{
    InputStreamReader reader = new InputStreamReader(input, Charset.forName("UTF-8"));
    CSVParser csv = new CSVParser(reader, CSVStrategy.EXCEL_STRATEGY);
    String[][] data = csv.getAllValues();
    if(data != null && data.length > 0)
    {
        processSpreadsheetUpload(data, users);
    }
}
项目:secure-data-service    文件:CcsCsvReader.java   
void load() throws IOException {
    File file = new File(fileLocation);
    file = removeEmptyLinesFromCsv(file);
    if (containsCopyright) {
        copyright = removeTrailingCharacters(tail(file), ',');
        file = removeLastLine(file);
    }
    InputStreamReader isReader = new InputStreamReader(new FileInputStream(file), "UTF-8");
    csvParser = new CSVParser(isReader, CSVStrategy.EXCEL_STRATEGY);

    firstLine = csvParser.getLine();
    getNextRecord();
}
项目:hadoop-solr    文件:CSVIngestMapper.java   
@Override
public void configure(JobConf conf) {
  super.configure(conf);
  idField = conf.get("idField", "id");
  collection = conf.get(COLLECTION);
  if (collection == null) {
    throw new RuntimeException("No collection specified, aborting");
  }
  ignoreFirstLine = Boolean.parseBoolean(conf.get(CSV_IGNORE_FIRST_LINE_COMMENT, "false"));
  String delimiterStr = conf.get(CSV_DELIMITER);
  if (delimiterStr != null) {
    byte[] delimiterBase64 = Base64.decodeBase64(delimiterStr.getBytes());
    delimiterStr = new String(delimiterBase64);
  }

  // we get a string, but we only use the first character, as delimiters must be a 'char'
  String fieldMapStr = conf.get(CSV_FIELD_MAPPING);

  if (fieldMapStr == null) {
    log.warn("No field mapping specified, mapping to generic names, i.e. field_1, field_2, etc");
    fieldMap = Collections.emptyMap();
  } else {
    fieldMap = parseFieldMapStr(fieldMapStr);
  }
  String stratStr = conf.get(CSV_STRATEGY, DEFAULT_STRATEGY);
  if (stratStr.equalsIgnoreCase(DEFAULT_STRATEGY)) {
    strategy = CSVStrategy.DEFAULT_STRATEGY;
    // Only change the delimiter for DEFAULT and EXCEL
    if (delimiterStr != null && !delimiterStr.isEmpty() && !delimiterStr
        .equals(strategy.getDelimiter() + "")) {
      strategy.setDelimiter(delimiterStr.charAt(0));
    }
  } else if (stratStr.equalsIgnoreCase(EXCEL_STRATEGY)) {
    strategy = CSVStrategy.EXCEL_STRATEGY;
    if (delimiterStr != null && !delimiterStr.isEmpty() && !delimiterStr
        .equals(strategy.getDelimiter() + "")) {
      strategy.setDelimiter(delimiterStr.charAt(0));
    }
  } else if (stratStr.equalsIgnoreCase(TAB_DELIM_STRATEGY)) {
    strategy = CSVStrategy.TDF_STRATEGY;
  } else {
    try {
      Class<? extends CSVStrategy> stratClass = Class.forName(stratStr)
          .asSubclass(CSVStrategy.class);
      strategy = stratClass.newInstance();
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
      log.error("Exception", e);
      throw new RuntimeException("Couldn't load CSVStrategy class, aborting");
    }
  }
}
项目:alfresco-remote-api    文件:DeclarativeSpreadsheetWebScript.java   
/**
 * Set the CSVStrategy
 * 
 * @param csvStrategy CSVStrategy
 */
public void setCsvStrategy(CSVStrategy csvStrategy)
{
    this.csvStrategy = csvStrategy;
}
项目:community-edition-old    文件:DeclarativeSpreadsheetWebScript.java   
/**
 * Set the CSVStrategy
 * 
 * @param csvStrategy CSVStrategy
 */
public void setCsvStrategy(CSVStrategy csvStrategy)
{
    this.csvStrategy = csvStrategy;
}