当前位置: 首页>>代码示例>>Java>>正文


Java CSVFormat.DEFAULT属性代码示例

本文整理汇总了Java中org.apache.commons.csv.CSVFormat.DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java CSVFormat.DEFAULT属性的具体用法?Java CSVFormat.DEFAULT怎么用?Java CSVFormat.DEFAULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.commons.csv.CSVFormat的用法示例。


在下文中一共展示了CSVFormat.DEFAULT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: csvToObject

public T csvToObject(InputStream is) throws IOException, IllegalArgumentException, IllegalAccessException, InstantiationException {
    WrapperReturner<T> list = new WrapperReturner();
       try (InputStreamReader br = new InputStreamReader(is)) {
        CSVParser parser = new CSVParser(br, CSVFormat.DEFAULT);
        for (int i = 0, j = 0; i < parser.getRecordNumber(); i++) {
            j = 0;
            for (Field field : classFields) {
                setFieldValue(field, list.t, parser.getRecords().get(i).get(j));
                list.tl.add(list.t);
                j++;
            }
        }

    }
    return list.t;
}
 
开发者ID:stoiandan,项目名称:OnlineShop,代码行数:16,代码来源:CSVProcessor.java

示例2: appendCSV

/**
 * this method is used to append pending transactions to the csv file
 * @param trans
 */
public void appendCSV(UserStockTransaction trans){
	try{
		
		filePath = servletContext.getRealPath("WEB-INF/csv/pending.csv");
		File f = new File(filePath);
		//System.out.println(trans.getStock().getSymbol() + " " + trans.getUser().getUsername() + " " + trans.getPrice());
		
		FileWriter fw = new FileWriter(f, true);			
		CSVPrinter cp = new CSVPrinter(fw, CSVFormat.DEFAULT);
		System.out.println("Appending a transaction");
		System.out.println(trans.toString());
		cp.printRecord((Object[]) trans.toString().split(","));
		fw.flush();
		fw.close();
		cp.close();
	}catch (Exception e){
		e.printStackTrace();
	}
}
 
开发者ID:yyang325,项目名称:YahooFinanceTradingSystem,代码行数:23,代码来源:CsvUtil.java

示例3: rewriteCSV

/**
 * this method is used to rewrite the csv file for all the pending transactions
 * @param trans
 */
public void rewriteCSV(List<UserStockTransaction> trans){
	try{
		
		filePath = servletContext.getRealPath("WEB-INF/csv/pending.csv");
		File f = new File(filePath);
		
		FileWriter fw = new FileWriter(f);			
		CSVPrinter cp = new CSVPrinter(fw, CSVFormat.DEFAULT);
		System.out.println(trans.toString());
		for(UserStockTransaction tx: trans){
			cp.printRecord((Object[]) tx.toString().split(","));
		}
		fw.flush();
		fw.close();
		cp.close();			
	}catch (Exception e){
		e.printStackTrace();
	}
}
 
开发者ID:yyang325,项目名称:YahooFinanceTradingSystem,代码行数:23,代码来源:CsvUtil.java

示例4: postcodeToLatLong

public static Map<String, LatLong> postcodeToLatLong(String datasetProvider, DownloadUtils downloadUtils) throws Exception {
    Map<String, LatLong> postcodeToCoordMap = new HashMap<>();
    InputStreamReader postcodeIsr = new InputStreamReader(downloadUtils.fetchInputStream(new URL(POSTCODE_TO_COORDINATE_URL), datasetProvider, ".csv"));

    CSVParser csvFileParser = new CSVParser(postcodeIsr, CSVFormat.DEFAULT);
    Iterator<CSVRecord> iter = csvFileParser.getRecords().iterator();
    CSVRecord header = iter.next();

    while (iter.hasNext()) {
        CSVRecord record = iter.next();
        postcodeToCoordMap.put(record.get(1),
                new LatLong(record.get(2), record.get(3)));
    }

    return postcodeToCoordMap;
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:16,代码来源:CoordinateUtils.java

示例5: setupUtils

protected void setupUtils() throws Exception {
    CSVFormat format = CSVFormat.DEFAULT;
    String fileLocation = config.getFileLocation();
    URL url;
    try {
        url = new URL(fileLocation);
    } catch (MalformedURLException e) {
        File file;
        if (!(file = new File(fileLocation)).exists()) {
            log.error("File does not exist: ", fileLocation);
        }
        url = file.toURI().toURL();
    }

    InputStreamReader isr = new InputStreamReader(
            downloadUtils.fetchInputStream(url, getProvider().getLabel(), ".csv"));
    CSVParser csvFileParser = new CSVParser(isr, format);
    csvRecords = csvFileParser.getRecords();
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:19,代码来源:GeneralCSVImporter.java

示例6: createCSVFile

/**
 * Method to create a csv file with the measurement result.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param outputFile
 * @param item
 * @throws IOException 
 */
public void createCSVFile(String outputFile, ItemMeasured item) throws IOException{

	setFolderPath();		
	populateHeader();
	
	File file = new File(tempFolderPath + outputFile + ".csv");
	if (!file.exists()){
		boolean isFileCreated = file.createNewFile();
		logger.info("File created " + isFileCreated);
	}
	
    try (FileWriter fileWriter = new FileWriter(file, true);
    	 CSVPrinter csvOutput = new CSVPrinter(fileWriter, CSVFormat.DEFAULT)) {
    	
   		csvOutput.printRecords(headerItems);
   		List<String[]> it = populateItems(item);
   		csvOutput.printRecords(it);
   		
   		JOptionPane.showMessageDialog(null, "CSV file was created successfully!");
        
    }catch (IOException exception) {
    	JOptionPane.showMessageDialog(null, "Error in CsvFileWriter!");
    	logger.error(exception);
	} 
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:33,代码来源:FileExport.java

示例7: splitStr

/**
 * String Parsing 
 */

public static String[] splitStr(String val, Integer len) throws IOException {
    
    String[] input;
    
    try {
        CSVParser parser = new CSVParser(new StringReader(val), CSVFormat.DEFAULT);
        CSVRecord record = parser.getRecords().get(0);
        input = new String[len];
        Iterator<String> valuesIt = record.iterator();
        int i = 0;
        while (valuesIt.hasNext()) {
            input[i] = valuesIt.next().trim();
            i++;
        }
        parser.close();
    } catch (ArrayIndexOutOfBoundsException e) {
        input = val.split(",", len);
        for (int i = 0; i < input.length; i++)
            input[i] = input[i].trim();
    }
    
    return input;
}
 
开发者ID:ViDA-NYU,项目名称:data-polygamy,代码行数:27,代码来源:FrameworkUtils.java

示例8: objectToCSV

public void objectToCSV(OutputStream os, T t) throws FileNotFoundException, IOException, IllegalAccessException {

        try (CSVPrinter printer = new CSVPrinter(new OutputStreamWriter(os), CSVFormat.DEFAULT)) {
            writeObjectHeader(printer);
            for (T element : t.tl) {
                Field last = classFields.remove(classFields.size() - 1);
                for (Field field : classFields) {
                    printer.print(getFieldValue(field, element));
                }
                printer.print(getFieldValue(last, element));
            }
        }
    }
 
开发者ID:stoiandan,项目名称:OnlineShop,代码行数:13,代码来源:CSVProcessor.java

示例9: readCSV

/**
 * test readCSV() function
 * @return
 */
public String readCSV(){
	StringBuffer sb = new StringBuffer();
	
	try{
		filePath = servletContext.getRealPath("WEB-INF/csv/pending.csv");
		
		File f = new File(filePath);
		
		System.out.println(f.exists());

		FileReader fr = new FileReader(f);
		CSVParser parser = new CSVParser(fr, CSVFormat.DEFAULT);
	   
	    List<CSVRecord> l = parser.getRecords();
		for (CSVRecord r:l){
			System.out.println(r);
			sb.append(r.get(0));
			//sb.append(r.get(1));
			sb.append(r.get(2));
			sb.append(r.get(3));
			sb.append(r.get(4));
			sb.append("| ");
		}
		fr.close();
		parser.close();
		
	}catch (Exception e){
		e.printStackTrace();
	}
	return sb.toString();
}
 
开发者ID:yyang325,项目名称:YahooFinanceTradingSystem,代码行数:35,代码来源:CsvUtil.java

示例10: loadSchema

private void loadSchema() {
    String versionsFilePath = "/versions.csv";
    try (CSVParser parser = new CSVParser(new InputStreamReader(getClass().getResourceAsStream(versionsFilePath)), CSVFormat.DEFAULT)) {
        for (CSVRecord record : parser.getRecords()) {
            String name = record.get(0);
            String className = record.get(1);
            controller.registerVersion(name, className);
        }
    } catch (Exception e) {
        String msg = versionsFilePath + " read error";
        log.log(Level.WARNING, msg, e);
        Dialogs.showException(Alert.AlertType.WARNING, msg, e.getMessage(), e);
    }
}
 
开发者ID:acmi,项目名称:xdat_editor,代码行数:14,代码来源:XdatEditor.java

示例11: serialize

@Override
public byte[] serialize(final String topic, final GenericRow genericRow) {
  if (genericRow == null) {
    return null;
  }
  try {
    StringWriter stringWriter = new StringWriter();
    CSVPrinter csvPrinter = new CSVPrinter(stringWriter, CSVFormat.DEFAULT);
    csvPrinter.printRecord(genericRow.getColumns());
    return stringWriter.toString().getBytes(StandardCharsets.UTF_8);
  } catch (Exception e) {
    throw new SerializationException("Error serializing CSV message", e);
  }

}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:15,代码来源:KsqlDelimitedSerializer.java

示例12: dumpFeatures

public void dumpFeatures(List<FullyResolvedEntry> entries, FileProvider.FeatureSet output) throws IOException {
    FileWriter svmOutput = new FileWriter(output.SVMFeat);
    CSVPrinter csvPrinter = new CSVPrinter(new FileWriter(output.CSVFeat), CSVFormat.DEFAULT);
    CSVPrinter indexPrinter = new CSVPrinter(new FileWriter(output.index), CSVFormat.DEFAULT);

    for (FullyResolvedEntry entry : entries) {
        int order = 0;
        for (User user : entry.candidates) {
            indexPrinter.printRecord(entry.resource.getIdentifier(), user.getId(), user.getScreenName());
            boolean isPositive = user.getScreenName().equals(entry.entry.twitterId);
            double[] features = entry.features.get(order);

            csvPrinter.print(isPositive ? 1 : 0);
            svmOutput.write(String.valueOf(isPositive ? 1 : 0));
            for (int i = 0; i < features.length; i++) {
                csvPrinter.print(features[i]);
                svmOutput.write(" " + (i + 1) + ":");
                svmOutput.write(String.valueOf(features[i]));
            }
            svmOutput.write('\n');
            csvPrinter.println();
            order++;
        }
    }
    IOUtils.closeQuietly(svmOutput);
    indexPrinter.close();
    csvPrinter.close();
}
 
开发者ID:Remper,项目名称:sociallink,代码行数:28,代码来源:Evaluate.java

示例13: buildBeamSqlTable

@Override public BeamSqlTable buildBeamSqlTable(Table table) {
  BeamRecordSqlType recordType = getBeamSqlRecordTypeFromTable(table);

  String filePattern = table.getLocationAsString();
  CSVFormat format = CSVFormat.DEFAULT;
  JSONObject properties = table.getProperties();
  String csvFormatStr = properties.getString("format");
  if (csvFormatStr != null && !csvFormatStr.isEmpty()) {
    format = CSVFormat.valueOf(csvFormatStr);
  }

  BeamTextCSVTable txtTable = new BeamTextCSVTable(recordType, filePattern, format);
  return txtTable;
}
 
开发者ID:apache,项目名称:beam,代码行数:14,代码来源:TextTableProvider.java

示例14: printToCSV

/**
 * Creates a list of headers, prints the headers, then prints the records for each header.
 * If a record doesn't exist for a header, a blank space is put in its place
 *
 * @param parser
 * @param target
 * @throws IOException
 */
void printToCSV(Parser parser, PrintStream target) throws IOException {
    Map<String, String> curr = parser.next();

    List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();

    Set<String> CSV_HEADERS = new TreeSet<>();
    // Get headers and create list
    while (curr != null) {
        mapList.add(curr);
        for (String str : curr.keySet()) {
            CSV_HEADERS.add(str);
        }
        curr = parser.next();
    }

    CSVFormat csvFormat = CSVFormat.DEFAULT;
    CSVPrinter printer = new CSVPrinter(target, csvFormat);
    printer.printRecord(CSV_HEADERS);

    // Cycle through array of maps printing value for each header
    for (Map<String, String> map : mapList) {
        List<String> values = new ArrayList<String>();
        for (String header : CSV_HEADERS) {
            String value = StringUtils.trimToEmpty(map.get(header));
            values.add(value);
        }
        printer.printRecord(values.toArray());
    }
}
 
开发者ID:sonalake,项目名称:utah-parser,代码行数:37,代码来源:CommandLineInterface.java

示例15: processElement

@ProcessElement
public void processElement(ProcessContext c) {
	
	ContentIndexSummary summary = c.element();

	if (summary.sentiments == null) 
		return;
	
	try {
	
		StringWriter stringWriter = new StringWriter();
		CSVPrinter csvPrinter = new CSVPrinter(stringWriter,CSVFormat.DEFAULT);
			
		for (int i=0; i < summary.sentiments.length; i++)
		{
			
			ArrayList<String> linefields = new ArrayList<String>();
			
			addField(linefields,"RecordID",summary.doc.collectionItemId);
	
			ArrayList<String> sttags = new ArrayList<>();
			if (summary.sentiments[i].tags != null) 
				for (int j=0; j < summary.sentiments[i].tags.length; j++)
					sttags.add(summary.sentiments[i].tags[j].tag);
			
			addField(linefields,"Tags",sttags.toString()); // will write as [a,b,c]
			
			addField(linefields,"SentimentHash", summary.sentiments[i].sentimentHash);
			addField(linefields,"Text", summary.sentiments[i].text);
			addField(linefields,"LabelledPositions", summary.sentiments[i].labelledPositions);
			addField(linefields,"AnnotatedText", summary.sentiments[i].annotatedText);
			addField(linefields,"AnnotatedHtml", summary.sentiments[i].annotatedHtmlText);
			addField(linefields,"SentimentTotalScore", summary.sentiments[i].sentimentTotalScore);
			addField(linefields,"DominantValence", summary.sentiments[i].dominantValence.ordinal());
			addField(linefields,"StAcceptance", summary.sentiments[i].stAcceptance);
			addField(linefields,"StAnger", summary.sentiments[i].stAnger);
			addField(linefields,"StAnticipation", summary.sentiments[i].stAnticipation);
			addField(linefields,"StAmbiguous", summary.sentiments[i].stAmbiguous);
			addField(linefields,"StDisgust", summary.sentiments[i].stDisgust);
			addField(linefields,"StFear", summary.sentiments[i].stFear);
			addField(linefields,"StGuilt", summary.sentiments[i].stGuilt);
			addField(linefields,"StInterest", summary.sentiments[i].stInterest);
			addField(linefields,"StJoy", summary.sentiments[i].stJoy);
			addField(linefields,"StSadness", summary.sentiments[i].stSadness);
			addField(linefields,"StShame", summary.sentiments[i].stShame);
			addField(linefields,"StSurprise", summary.sentiments[i].stSurprise);
			addField(linefields,"StPositive", summary.sentiments[i].stPositive);
			addField(linefields,"StNegative", summary.sentiments[i].stNegative);
			addField(linefields,"StSentiment", summary.sentiments[i].stSentiment);
			addField(linefields,"StProfane", summary.sentiments[i].stProfane);
			addField(linefields,"StUnsafe", summary.sentiments[i].stUnsafe);
			
			ArrayList<String> signalsarray = new ArrayList<>();
			if (summary.sentiments[i].signals != null) 
				for (int j=0; j < summary.sentiments[i].signals.length; j++)
					signalsarray.add(summary.sentiments[i].signals[j]);
			
			addField(linefields,"Signals",signalsarray.toString());
			
			csvPrinter.printRecord(linefields);
			
			String output = stringWriter.toString().trim(); // need to trim, because printRecord will add the record separator, as will the TextIO.write method at the end of the pipeline
			csvPrinter.flush(); // will also flush the stringWriter
			
			c.output(output);
			
			
		}
		
		csvPrinter.close();
	} catch (IOException e) {
		LOG.warn(e.getMessage());
	}
}
 
开发者ID:GoogleCloudPlatform,项目名称:dataflow-opinion-analysis,代码行数:74,代码来源:FileIndexerPipeline.java


注:本文中的org.apache.commons.csv.CSVFormat.DEFAULT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。