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


Java CSVReader.close方法代碼示例

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


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

示例1: loadCSV

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
private void loadCSV(File fpIn, Map<Integer,Double> mapForB, Map<Integer,Double> mapForD,
		Map<Integer,Double> mapForR ) throws IOException {
	assertTrue(fpIn.exists());
	CSVReader reader = new CSVReader(new FileReader(fpIn));
	String[] nextLine;
	while ((nextLine = reader.readNext()) != null) {
		String order = nextLine[1].trim();
		switch (order) {
		case PLACEHOLDER_B : mapForB.put(Integer.parseInt(nextLine[0]), Double.parseDouble(nextLine[2]));
							break;
		case PLACEHOLDER_D : mapForD.put(Integer.parseInt(nextLine[0]), Double.parseDouble(nextLine[2]));
							break;
		case PLACEHOLDER_R : mapForR.put(Integer.parseInt(nextLine[0]), Double.parseDouble(nextLine[2]));
							break;
		}
	}
	assertTrue(mapForB.size() > 0);
	assertEquals(mapForB.size(), mapForD.size());
	assertEquals(mapForD.size(), mapForR.size());
	reader.close();
}
 
開發者ID:isislab-unisa,項目名稱:streaminggraphpartitioning,代碼行數:22,代碼來源:StantonAppTest.java

示例2: extractRandomConfigs

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的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

示例3: fromStream

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * Generate ReportData from an input stream (normally an HTTP steam of report in CSV format),
 * which will be closed after reading.
 * @param stream the input stream (in CSV format)
 * @param clientCustomerId the client customer ID of this report
 * @return the generated ReportData
 */
public ReportData fromStream(InputStream stream, Long clientCustomerId) throws IOException {
  CSVReader csvReader = new CSVReader(new InputStreamReader(stream, Charset.defaultCharset()));
  String[] headerArray = csvReader.readNext();
  List<String[]> rowsArray = csvReader.readAll();
  csvReader.close();

  int rowsCount = rowsArray.size();
  List<List<String>> rows = new ArrayList<List<String>>(rowsCount);
  for (int i = 0; i < rowsCount; ++i) {
    // need to create a new ArrayList object which is extendible.
    List<String> row = new ArrayList<String>(Arrays.asList(rowsArray.get(i)));
    rows.add(row);
  }

  int columns = headerArray.length;
  List<String> columnNames = new ArrayList<String>(columns);
  for (int i = 0; i < columns; i++) {
    String fieldName = fieldsMapping.get(headerArray[i]);
    Preconditions.checkNotNull(fieldName, "Unknown field name: %s.", fieldName);
    columnNames.add(fieldName);
  }

  return new ReportData(clientCustomerId, reportType, columnNames, rows);
}
 
開發者ID:googleads,項目名稱:adwords-alerting,代碼行數:32,代碼來源:ReportDataLoader.java

示例4: testProcessLineWrongNumberOfFields

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Test
public final void testProcessLineWrongNumberOfFields() throws Exception {
	setUp();
	CSVReader reader = metadataLoader.createReader();
	String[] metadataFields = metadataLoader.readMetadataFields(reader);

	String[] line = {"a"};
	try {
		metadataLoader.processLine(line, metadataFields);
	} catch (Throwable e) {
		assert(true);
		return;
	}
	assert(false);
	reader.close();
}
 
開發者ID:xenit-eu,項目名稱:move2alf,代碼行數:17,代碼來源:CSVMetadataLoaderTest.java

示例5: testProcessLine

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Test
public final void testProcessLine() throws Exception {
	setUp();
	CSVReader reader = metadataLoader.createReader();
	String[] metadataFields = metadataLoader.readMetadataFields(reader);
	HashMap parameterMap = new HashMap();

	String[] line = {"/home/rox/m2a-dev-tutorial/input-csv/file1.txt","metadata11","metadata21","metadata31"};
	metadataLoader.processLine(line, metadataFields);

	assertEquals("/home/rox/m2a-dev-tutorial/input-csv/file1.txt",((File)(parameterMap.get(Parameters.PARAM_FILE))).getAbsolutePath());
	HashMap<String,String> metadata = (HashMap)parameterMap.get(Parameters.PARAM_METADATA);
	assertEquals("metadata11",metadata.get(metadataFields[1]));
	assertEquals("metadata21",metadata.get(metadataFields[2]));
	assertEquals("metadata31",metadata.get(metadataFields[3]));
	reader.close();
}
 
開發者ID:xenit-eu,項目名稱:move2alf,代碼行數:18,代碼來源:CSVMetadataLoaderTest.java

示例6: HITDataCSVReader

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public HITDataCSVReader(String fileName, char separator) throws IOException {
    super();
    InputStreamReader input = new InputStreamReader(new FileInputStream(fileName), "UTF-8");
    CSVReader csvReader = new CSVReader(input, separator, CSVWriter.DEFAULT_QUOTE_CHARACTER);
    String[] row = null;
    
    try {
      // read all lines but skip header rows that got appended repetitively
      while ((row = csvReader.readNext()) != null) {
        if (fieldNames == null) {
          fieldNames = row;
          rows.add(fieldNames); // header is at index 0
        }
        else if (!Arrays.equals(fieldNames, row)) {
          rows.add(row);
        }
      }
    }
    finally {
      csvReader.close();
    }
}
 
開發者ID:dbarowy,項目名稱:java-aws-mturk,代碼行數:23,代碼來源:HITDataCSVReader.java

示例7: loadSyllableDict

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
private void loadSyllableDict() throws IOException {
	/**
	 * Load in syllable dictionary using OpenCSV library. Place the array
	 * into a dictionary.
	 */
	String csvPath = "/com/org/watsonwrite/lawrence/resources/syllables.txt";
	InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream(csvPath));
	BufferedReader br = new BufferedReader(isr);

	CSVReader reader = new CSVReader(br);
	String[] nextLine;
	while ((nextLine = reader.readNext()) != null) {
		syllables.put(nextLine[0], Integer.parseInt(nextLine[1]));
	}
	reader.close();
}
 
開發者ID:troywatson,項目名稱:Lawrence-Style-Checker,代碼行數:17,代碼來源:Lawrence.java

示例8: read

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
private void read() throws IOException
{
    if (firstRead)
    {
        CSVReader reader = new CSVReader(new FileReader(NameFactory.CONF_PATH_FILE));
        List<String[]> items = reader.readAll();
        confItems = new ArrayList<>();
        for (String[] item : items)
        {
            ConfItem confItem = createConfItem(item);
            Logger.traceINFO(confItem.toString());
            confItems.add(confItem);
        }

        reader.close();
        firstRead = false;
    }
}
 
開發者ID:philipperemy,項目名稱:Leboncoin,代碼行數:19,代碼來源:ConfReader.java

示例9: read

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static List<SoundEvent> read(String file, SoundEvent.Type type) throws IOException{
    List<SoundEvent> events = new ArrayList<SoundEvent>();

    CSVReader reader = new CSVReader(new FileReader(file));
    String [] nextLine;
    
    while ((nextLine = reader.readNext()) != null) {
        if(!isString(nextLine)){
            SoundEvent e = new SoundEvent(nextLine[0], nextLine[1]);
            e.type = type;
            events.add(e);
        }
    }
    reader.close();
    
    return events;
}
 
開發者ID:vocobox,項目名稱:vocobox,代碼行數:18,代碼來源:SoundEventReader.java

示例10: getPersistedObjects

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public List<PersistedObject> getPersistedObjects()
{
    List<PersistedObject> persistedObjects = new ArrayList<>();
    try
    {
        CSVReader reader = new CSVReader(new FileReader(NameFactory.PERSISTENCE_CSV));
        List<String[]> allEntries = reader.readAll();
        reader.close();
        for (String[] entry : allEntries)
        {
            persistedObjects.add(new PersistedObject(entry[1], entry[0]));
        }
    }
    catch (Exception e)
    {
        App.kill(e);
    }

    return persistedObjects;
}
 
開發者ID:philipperemy,項目名稱:Leboncoin,代碼行數:21,代碼來源:Persistence.java

示例11: persist

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的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: importCsv

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static SortedMap<Number, Number> importCsv(String filePath) {
	try {
		reader = new CSVReader(new FileReader(filePath));
		List<String[]> entries = reader.readAll();
		SortedMap<Number, Number> data = new TreeMap<>();

		for (String[] line : entries) {
			if (line.length == 2) {
				Number x = NumberFormat.getNumberInstance(LOCALE).parse(line[0]);
				Number y = NumberFormat.getNumberInstance(LOCALE).parse(line[1]);
				data.put(x, y);
			}
		}

		reader.close();
		return data;
	} catch (IOException | ParseException e) {
		System.err.println(e.getMessage());
	}
	return Collections.emptySortedMap();
}
 
開發者ID:tesis-dynaware,項目名稱:fancy-chart,代碼行數:22,代碼來源:CsvDao.java

示例13: parseDatei

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * Initialer Aufruf, der die Datei parst. Wird von den Implementierungen der
 * Interfaces aufgerufen.
 * 
 * @param in
 *            InputStream für die einzulesende Datei
 */
protected void parseDatei(InputStream in) throws IOException {
    // Momentan statisch mit Semikolon als Delimiter
    reader = new CSVReader(new InputStreamReader(in, "ISO-8859-1"), ';');
    String[] curLine;
    aktuelleZeile = beginneBeiZeile;
    for (int i = 0; i < beginneBeiZeile; i++) {
        curLine = reader.readNext();
    }
    while (null != (curLine = reader.readNext())) {
        if (curLine.length > 1) {
            this.parseZeile(curLine);
        }
        aktuelleZeile++;
    }

    // Am Schluss:
    reader.close();
    this.dateiendeErreicht();

}
 
開發者ID:Bundeswahlrechner,項目名稱:Bundeswahlrechner,代碼行數:28,代碼來源:CSVParser.java

示例14: getHeader

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public  String[][] getHeader(String filename) throws IOException {
  CSVReader reader = new CSVReader(new FileReader(filename));
  String[] data =  reader.readNext();
  if (data == null)
    return null;
  String[][] headers = new String[4][data.length];
  headers[0]=data;
  headers[1]= reader.readNext();
  headers[2]= reader.readNext();
  headers[3]= reader.readNext();
  if (headers[0]==null||headers[1]==null ||headers[2]==null||headers[3]==null) {
    logger.debug("Header read incompletely.");
    logger.debug(""+(headers[0]==null));
    logger.debug(""+(headers[1]==null));
    logger.debug(""+(headers[2]==null));
    logger.debug(""+(headers[3]==null));
    return null;
  }
  reader.close();
  return headers;
}
 
開發者ID:LSIR,項目名稱:gsn,代碼行數:22,代碼來源:WanWrapper.java

示例15: closeReader

import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
private void closeReader(final Reader in, final CSVReader reader) {
  try {
    if (reader != null) {
      reader.close();
    }
    if (in != null) {
      in.close();
    }
  } catch (final IOException e) {
    LOG.error(e.getMessage());
  }
}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:13,代碼來源:RBACRetrievalServiceMemoryImpl.java


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