本文整理汇总了Java中com.csvreader.CsvReader.readRecord方法的典型用法代码示例。如果您正苦于以下问题:Java CsvReader.readRecord方法的具体用法?Java CsvReader.readRecord怎么用?Java CsvReader.readRecord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.csvreader.CsvReader
的用法示例。
在下文中一共展示了CsvReader.readRecord方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test82
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test82() throws Exception {
StringBuilder holder = new StringBuilder(200010);
for (int i = 0; i < 100000; i++) {
holder.append("a,");
}
holder.append("a");
CsvReader reader = CsvReader.parse(holder.toString());
try {
reader.readRecord();
} catch (Exception ex) {
assertException(
new IOException(
"Maximum column count of 100,000 exceeded in record 0. Set the SafetySwitch property to false if you're expecting more than 100,000 columns per record to avoid this error."),
ex);
}
reader.close();
}
示例2: test91
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test91() throws Exception {
byte[] buffer;
String test = "test";
ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(stream);
writer.println(test);
writer.close();
buffer = stream.toByteArray();
stream.close();
CsvReader reader = new CsvReader(new ByteArrayInputStream(buffer),
Charset.forName("ISO-8859-1"));
reader.readRecord();
Assert.assertEquals(test, reader.get(0));
reader.close();
}
示例3: test92
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test92() throws Exception {
byte[] buffer;
String test = "test";
ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(stream);
writer.println(test);
writer.close();
buffer = stream.toByteArray();
stream.close();
CsvReader reader = new CsvReader(new ByteArrayInputStream(buffer), ',',
Charset.forName("ISO-8859-1"));
reader.readRecord();
Assert.assertEquals(test, reader.get(0));
reader.close();
}
示例4: init
import com.csvreader.CsvReader; //导入方法依赖的package包/类
/**
* 存储数据进入InfoMap这个HashMap的操作逻辑
*
* @param activity 本参数传入以便获得raw文本数据(可能传入流的引用更符合设计模式
* @throws IOException
*/
public void init(MainActivity activity) throws IOException {
Connector.getDatabase();
InputStream inputStream = activity.getResources().openRawResource(R.raw.foods);
CsvReader csvReader = new CsvReader(new InputStreamReader(inputStream));
ArrayList<String[]> list = new ArrayList<>();
while (csvReader.readRecord()) {//将csv数据读取到列表中
list.add(csvReader.getValues());
}
csvReader.close();
inputStream.close();
addDataAll(list);//把HashMap中的食物属性信息存入LiteSQL数据库中
}
示例5: test79
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test79() {
CsvReader reader;
reader = CsvReader.parse("");
reader.close();
try {
reader.readRecord();
} catch (Exception ex) {
assertException(
new IOException(
"This instance of the CsvReader class has already been closed."),
ex);
}
}
示例6: test81
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test81() throws Exception {
CsvReader reader = CsvReader.parse(generateString('a', 100001));
try {
reader.readRecord();
} catch (Exception ex) {
assertException(
new IOException(
"Maximum column length of 100,000 exceeded in column 0 in record 0. Set the SafetySwitch property to false if you're expecting column lengths greater than 100,000 characters to avoid this error."),
ex);
}
reader.close();
}
示例7: test83
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test83() throws Exception {
CsvReader reader = CsvReader.parse(generateString('a', 100001));
reader.setSafetySwitch(false);
reader.readRecord();
reader.close();
}
示例8: test84
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test84() throws Exception {
StringBuilder holder = new StringBuilder(200010);
for (int i = 0; i < 100000; i++) {
holder.append("a,");
}
holder.append("a");
CsvReader reader = CsvReader.parse(holder.toString());
reader.setSafetySwitch(false);
reader.readRecord();
reader.close();
}
示例9: test86
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test86() throws Exception {
StringBuilder holder = new StringBuilder(200010);
for (int i = 0; i < 99999; i++) {
holder.append("a,");
}
holder.append("a");
CsvReader reader = CsvReader.parse(holder.toString());
reader.readRecord();
reader.close();
}
示例10: test143
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test143() throws Exception {
CsvReader reader = CsvReader.parse("\"" + generateString('a', 100001)
+ "\"");
try
{
reader.readRecord();
}
catch (Exception ex)
{
assertException(new IOException("Maximum column length of 100,000 exceeded in column 0 in record 0. Set the SafetySwitch property to false if you're expecting column lengths greater than 100,000 characters to avoid this error."), ex);
}
reader.close();
}
示例11: parseData
import com.csvreader.CsvReader; //导入方法依赖的package包/类
public static List<RawDataEntry> parseData(String filepath)
throws FileNotFoundException {
List<RawDataEntry> libreEntrys = new ArrayList<>();
// read file
CsvReader creader = new CsvReader(filepath, '\t', Charset.forName("UTF-8"));
// TODO add stuff
// Teststreifen-Blutzucker (mg/dL)
// Keton (mmol/L)
try {
// validate header
// TODO implement a header-erkenner
for (int i = 0; i < 2; i++) {
creader.readHeaders();
//TODO compute meta data
}
//TODO check header data
// if (!CsvValidator.validateCarelinkHeader(creader)) {
// Logger.getLogger(CarelinkCsvImporter.class.getName()).
// log(Level.SEVERE,
// "Stop parser because of unvalid header:\n"
// + Arrays.toString(Constants.CARELINK_CSV_HEADER[0])
// + "\n{0}", creader.getRawRecord());
// return null;
// }
// read entries
while (creader.readRecord()) {
// Todo cathegorize entry
RawDataEntry entry = parseEntry(creader);
if (entry != null) {
libreEntrys.add(entry);
Logger.getLogger(MedtronicCsvImporter.class.getName()).log(
Level.INFO, "Got Entry: {0}", entry.toString());
} else {
// Logger.getLogger(CarelinkCsvImporter.class.getName()).log(
// Level.FINE, "Drop Entry: {0}", creader.getRawRecord());
}
}
} catch (IOException | ParseException ex) {
Logger.getLogger(MedtronicCsvImporter.class.getName()).log(
Level.SEVERE, "Error while parsing Careling CSV", ex);
} finally {
creader.close();
}
return libreEntrys;
}
示例12: test85
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test85() throws Exception {
CsvReader reader = CsvReader.parse(generateString('a', 100000));
reader.readRecord();
reader.close();
}
示例13: processImport
import com.csvreader.CsvReader; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
protected boolean processImport(final InputStream fileInputStream, final String filenameForLogging) {
importedData = new ArrayList<>();
importedRawData = new ArrayList<>();
final int maxProgress = 100;
//This list is used as a placeholder for future extensions
List<String[]> metaEntries = new ArrayList<>();
this.notifyStatus(0, "Reading Header");
try {
CsvReader creader = null;
if (getDelimiter() == 0) { //try to detect the delimiter by trial and error
LOG.log(Level.INFO, "using automatic delimiter detection");
char[] delimiterList = {',', ';', '\t'};
for (char delimiter : delimiterList) {
creader = getValidatedCreader(delimiter, fileInputStream, metaEntries);
if (null != creader) {
setDelimiter(delimiter);
break;
}
}
} else { // use the delimiter that was set
creader = getValidatedCreader(getDelimiter(), fileInputStream, metaEntries);
}
if (creader == null) { //header could not be validated
LOG.log(Level.WARNING, "No valid header found in File:{0}", filenameForLogging);
return false;
}
// read entries
while (creader.readRecord()) {
/*here the method template is used to process all records */
List<VaultEntry> entryList = parseEntry(creader);
boolean entryIsInterpreted = false;
if (entryList != null && !entryList.isEmpty()) {
for (VaultEntry item : entryList) {
item.setRawId(importedRawData.size()); // add array position as raw id
importedData.add(item);
LOG.log(Level.FINE, "Got Entry: {0}", entryList.toString());
}
entryIsInterpreted = true;
}
importedRawData.add(new RawEntry(creader.getRawRecord(), entryIsInterpreted));
LOG.log(Level.FINER, "Put Raw: {0}", creader.getRawRecord());
}
this.notifyStatus(maxProgress, "Done importing all entries");
} catch (Exception ex) {
LOG.log(Level.WARNING, "Error while parsing CSV: "
+ filenameForLogging, ex);
}
return true;
}