當前位置: 首頁>>代碼示例>>Java>>正文


Java CSVWriter.close方法代碼示例

本文整理匯總了Java中au.com.bytecode.opencsv.CSVWriter.close方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVWriter.close方法的具體用法?Java CSVWriter.close怎麽用?Java CSVWriter.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在au.com.bytecode.opencsv.CSVWriter的用法示例。


在下文中一共展示了CSVWriter.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeCSV

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
 * Writes the data set to a CSV file
 * 
 * @param file
 * @param dataset
 * @throws IOException
 */
public void writeCSV(File file, DataSet<RecordType, SchemaElementType> dataset)
		throws IOException {
	CSVWriter writer = new CSVWriter(new FileWriter(file));

	String[] headers = getHeader(dataset);
	if(headers!=null) {
		writer.writeNext(headers);
	}

	for (RecordType record : dataset.get()) {
		String[] values = format(record, dataset);

		writer.writeNext(values);
	}

	writer.close();
}
 
開發者ID:olehmberg,項目名稱:winter,代碼行數:25,代碼來源:CSVDataSetFormatter.java

示例2: exportDatabaseToCsvString

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public synchronized String exportDatabaseToCsvString() {
    StringWriter stringWriter = new StringWriter();
    CSVWriter csvWriter = new CSVWriter(stringWriter);
    csvWriter.writeNext(ThreeThingsEntry.COLUMNS);

    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM " + ThreeThingsEntry.TABLE_NAME, null);
    while (cursor.moveToNext()) {
        List<String> data = new ArrayList(ThreeThingsEntry.COLUMNS.length);
        for (String column : ThreeThingsEntry.COLUMNS) {
            data.add(cursor.getString(cursor.getColumnIndexOrThrow(column)));
        }
        csvWriter.writeNext(data.toArray(new String[0]));
    }

    try {
        csvWriter.close();
    } catch (IOException e) {
        // Ignore.
    }

    return stringWriter.toString();
}
 
開發者ID:stephenmcgruer,項目名稱:three-things-today,代碼行數:24,代碼來源:ThreeThingsDatabase.java

示例3: writeCSVfile

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
 * Writes newly calculated and equally distributed vector data to user specified CSV file.
 *
 * @param list finalized vector data to write to user specified output file
 */
public static void writeCSVfile(List<List<String>> list) {
  String outputFile = myResultDir;
  boolean alreadyExists = new File(outputFile).exists();

  try {
    CSVWriter csvOutput = new CSVWriter(new FileWriter(outputFile), ','); // Create new instance of CSVWriter to write to file output

    if (!alreadyExists) {
      csvOutput.writeNext(myHeader); // Write the text headers first before data

      for (int i = 0; i < list.size(); i++) // Iterate through all rows in 2D array
      {
        String[] temp = new String[list.get(i).size()]; // Convert row array list in 2D array to regular string array
        temp = list.get(i).toArray(temp);
        csvOutput.writeNext(temp); // Write this array to the file
      }
    }

    csvOutput.close(); // Close csvWriter
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
開發者ID:apache,項目名稱:incubator-sdap-mudrod,代碼行數:29,代碼來源:DataGenerator.java

示例4: writeCSV

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
 * Writes the data set to a CSV file
 * 
 * @param file
 * @param dataset
 * @throws IOException
 */
public void writeCSV(File file, Processable<RecordType> dataset)
		throws IOException {
	CSVWriter writer = new CSVWriter(new FileWriter(file));

	String[] headers = getHeader();
	if(headers!=null) {
		writer.writeNext(headers);
	}

	for (RecordType record : dataset.get()) {
		String[] values = format(record);

		writer.writeNext(values);
	}

	writer.close();
}
 
開發者ID:olehmberg,項目名稱:winter,代碼行數:25,代碼來源:CSVFormatter.java

示例5: testDetails

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public void testDetails() throws IOException, InterruptedException {
	File fold = new File(FOLDER);
	CSVWriter wr = new CSVWriter(new FileWriter(new File(FOLDER + GRAPH_DETAILS)),'&');
	printHeader(wr);
	for (File fpin: fold.listFiles(p -> p.getName().endsWith(".graph"))) { 
		//if (fpin.getName().equals("auto.graph")) continue;
		log.info("Analyzing graph : " + fpin.getName());
		GraphAnalyser ga = new GraphAnalyser(new FileInputStream(fpin), wr, log);
		String grName = fpin.getName().substring(0, fpin.getName().length() - ".graph".length());
		ga.runLoad(grName);
		ga = null;
		System.gc();
	}
	
	wr.close();
}
 
開發者ID:isislab-unisa,項目名稱:streaminggraphpartitioning,代碼行數:17,代碼來源:AllGraphDetails.java

示例6: writeSimpleWeightedGraph2CSV

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static void writeSimpleWeightedGraph2CSV(SimpleWeightedGraph<Long, DefaultWeightedEdge> colocationgraph,
		File file) throws IOException {
	CSVWriter writer = new CSVWriter(new FileWriter(file), ';');
	// write header
	String[] line = new String[4];
	line[0] = "source";
	line[1] = "target";
	line[2] = "weight";
	line[3] = "type";
	writer.writeNext(line);
	for (DefaultWeightedEdge e : colocationgraph.edgeSet()) {
		line = new String[4];
		line[0] = String.valueOf(colocationgraph.getEdgeSource(e).longValue() + (long) 111);
		line[1] = String.valueOf(colocationgraph.getEdgeTarget(e).longValue() + (long) 111);
		line[2] = String.valueOf(colocationgraph.getEdgeWeight(e));
		line[3] = "undirected";
		writer.writeNext(line);
	}
	writer.close();
}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:21,代碼來源:SocialGraph.java

示例7: extractRandomConfigs

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static void extractRandomConfigs(String inputFile, String outputFile, int nConfigs, int nIterations) throws IOException{
	CSVReader lines = new CSVReader(new FileReader(inputFile), ',');
	List<String[]> content = lines.readAll();
	
	for (int i=0; i<nIterations;i++){
		System.out.println(content.isEmpty());
		// Shuffle list
		Collections.shuffle(content);
		int randomNum = ThreadLocalRandom.current().nextInt(1, content.size() - nConfigs);
		// Write lines
		CSVWriter writer = new CSVWriter(new FileWriter(outputFile+(i+1)+".csv", true),';');
		for(int j=randomNum;j<=randomNum+nConfigs-1;j++){
			writer.writeNext(content.get(j));
		}
		writer.close();
	}
	
	lines.close();
}
 
開發者ID:axel-halin,項目名稱:Thesis-JHipster,代碼行數:20,代碼來源:CSVUtils.java

示例8: getCustomerExportEmails

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@GET
@Path("export/emails")
// @Produces("text/plain")
public Response getCustomerExportEmails(@FilterParam Filter filter, @Context HttpServletResponse response)
    throws IOException {
    response.setContentType("text/csv");
    response.setHeader("Content-Disposition", "attachment; filename=\"customer-emails.csv\"");
    PrintWriter printWriter = response.getWriter();
    CSVWriter writer = new CSVWriter(printWriter, ';');
    writer.writeNext(new String[] { "E-mail" });

    List<Customer> customers = service.get(Customer.class);
    for (Customer customer : customers) {
        if (customer.getEmail() != null && !customer.getEmail().isEmpty()) {
            writer.writeNext(new String[] { customer.getEmail() });
        }
    }
    writer.flush();
    writer.close();

    return Response.ok().build();
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:23,代碼來源:CustomerResource.java

示例9: doRun

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
protected void doRun() throws Exception {
  CSVWriter csvWriter = new CSVWriter(new FileWriter(getCommandLine().getArgs()[0]));
  SecurityMaster securityMaster = getToolContext().getSecurityMaster();
  SecurityMetaDataRequest metaRequest = new SecurityMetaDataRequest();
  SecurityMetaDataResult metaData = securityMaster.metaData(metaRequest);
  for (String securityType : metaData.getSecurityTypes()) {
    s_logger.info("Processing security type " + securityType);
    SecuritySearchRequest searchRequest = new SecuritySearchRequest();
    searchRequest.setName("*");
    searchRequest.setSecurityType(securityType);
    searchRequest.setPagingRequest(PagingRequest.ONE);
    SecuritySearchResult search = securityMaster.search(searchRequest);
    s_logger.info("Search returned " + search.getPaging().getTotalItems() + " securities");
    dumpSecurityStructure(csvWriter, securityType, search.getFirstSecurity());
  }
  csvWriter.close();
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:19,代碼來源:SecurityFieldMappingTemplateGenerator.java

示例10: writeInternal

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
protected void writeInternal(QuoteWrapper quotes, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
    CSVWriter writer = new CSVWriter(new OutputStreamWriter(httpOutputMessage.getBody()));
    for (YahooQuote quote : quotes) {
        writer.writeNext(
        		new String[]{	quote.getId(),
        						quote.getName(),
        						String.valueOf(quote.getOpen()),
        						String.valueOf(quote.getPreviousClose()),
                				String.valueOf(quote.getLast()),
                        		String.valueOf(quote.getLastChange()),
                        		String.valueOf(quote.getLastChangePercent()),
                        		String.valueOf(quote.getHigh()),
                        		String.valueOf(quote.getLow()),
                        		String.valueOf(quote.getBid()),
                        		String.valueOf(quote.getAsk()),
                        		String.valueOf(quote.getVolume()),
        						quote.getExchange(),
        						quote.getCurrency()
        		});
    }

    writer.close();
}
 
開發者ID:alex-bretet,項目名稱:cloudstreetmarket.com,代碼行數:25,代碼來源:YahooQuoteMessageConverter.java

示例11: persist

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
private synchronized boolean persist(String id, String hash, boolean append) throws IOException
{
    // Append
    CSVReader reader = new CSVReader(new FileReader(NameFactory.PERSISTENCE_CSV));
    List<String[]> allEntries = reader.readAll();
    for (String[] entry : allEntries)
    {
        if (entry[0].equals(hash))
        {
            reader.close();
            return false;
        }
    }
    reader.close();

    CSVWriter writer = new CSVWriter(new FileWriter(NameFactory.PERSISTENCE_CSV, append));
    String[] entries = new String[2];
    entries[0] = hash;
    entries[1] = id;
    writer.writeNext(entries);
    writer.close();
    return true;
}
 
開發者ID:philipperemy,項目名稱:Leboncoin,代碼行數:24,代碼來源:Persistence.java

示例12: flush

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public synchronized void flush()
{
    try
    {
        CSVWriter writer = new CSVWriter(new FileWriter(NameFactory.PERSISTENCE_CSV, false));
        writer.close();
    }
    catch (IOException e)
    {
        Logger.traceERROR(e);
    }

    if (getSize() != 0)
    {
        Logger.traceERROR("PERSISTENCE - Persistence flush failed. Program will exit.");
        App.kill();
    }
}
 
開發者ID:philipperemy,項目名稱:Leboncoin,代碼行數:19,代碼來源:Persistence.java

示例13: writeCSV

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public void writeCSV(File file) throws IOException {
   	FileWriter writer = new FileWriter(file);
   	CSVWriter csvWriter = new CSVWriter(writer);
   	
	for (QueryLogValue query : queryLogStatistic.getLastQueries()) {
		String[] cols = new String[] {
				String.valueOf(query.isError()),
				query.getQueryString(),
				query.getFacetQueryString(),
				query.getFilterQueryString(),
				query.getQTime().toString(),
				query.getResults().toString()
		};
		csvWriter.writeNext(cols);
	}
	
	csvWriter.close();
}
 
開發者ID:lafourchette,項目名稱:solrmeter,代碼行數:19,代碼來源:FullQueryStatisticController.java

示例14: close

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public void close()
{
    for(String key : urls_trace_files.keySet())
    {
        CSVWriter writer = this.urls_trace_files.get(key);
        if(writer != null){
            try {
                writer.close();
            } catch (IOException ex) {
                LOG.log(Level.SEVERE, ex.getMessage(), ex);                    
            }
            urls_trace_files.put(key, null);
        }            
    }
    urls_trace_files.clear();
    urls_trace_files = null;
}
 
開發者ID:eduardoguzman,項目名稱:sisob-data-extractor,代碼行數:18,代碼來源:CrawlerTrace.java

示例15: csv

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static String csv(List<List<String>> rows) {
  StringWriter sw = new StringWriter();
  CSVWriter writer = new CSVWriter(sw);
  try {
    List<String[]> elements = new ArrayList<String[]>();
    for (List<String> row : rows) {
      elements.add(row.toArray(new String[0]));
    }
    writer.writeAll(elements);
    return sw.toString();
  } finally {
    try {
      writer.close();
    } catch (IOException e) {
      Log.exception(e);
    }
  }
}
 
開發者ID:MachinePublishers,項目名稱:ScreenSlicer,代碼行數:19,代碼來源:Spreadsheet.java


注:本文中的au.com.bytecode.opencsv.CSVWriter.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。