本文整理汇总了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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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());
}
}