本文整理汇总了Java中com.univocity.parsers.fixed.FixedWidthParser类的典型用法代码示例。如果您正苦于以下问题:Java FixedWidthParser类的具体用法?Java FixedWidthParser怎么用?Java FixedWidthParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FixedWidthParser类属于com.univocity.parsers.fixed包,在下文中一共展示了FixedWidthParser类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isFixedWidth
import com.univocity.parsers.fixed.FixedWidthParser; //导入依赖的package包/类
@Test
public void isFixedWidth() {
String result = generatePersonFixedWidth();
FixedWidthParserSettings settings = new FixedWidthParserSettings(fixedWidthFields);
FixedWidthParser fixedWidthParser = new FixedWidthParser(settings);
List<String[]> parsedResult = fixedWidthParser.parseAll(new StringReader(result));
assertEquals(5, parsedResult.size());
}
示例2: fixedWidthFile
import com.univocity.parsers.fixed.FixedWidthParser; //导入依赖的package包/类
@Ignore("Parser seems to be randomly failing?")
@Test
public void fixedWidthFile() {
File file = generateFixedWidthFile();
FixedWidthParserSettings settings = new FixedWidthParserSettings(fixedWidthFields);
FixedWidthParser fixedWidthParser = new FixedWidthParser(settings);
List<String[]> parsedResult = fixedWidthParser.parseAll(file);
System.out.println(new ReadFile(file).getText());
assertEquals(printRows(parsedResult), 5, parsedResult.size());
}
示例3: init
import com.univocity.parsers.fixed.FixedWidthParser; //导入依赖的package包/类
private void init()
{
fields = new ArrayList<FixedWidthField>();
List<String> headers = new ArrayList<String>();
List<Integer> fieldWidth = new ArrayList<Integer>();
for (String tmp : fieldDescription.split(",")) {
String[] fieldTuple = tmp.split(":(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1);
FixedWidthField field = new FixedWidthField();
field.setName(fieldTuple[0]);
field.setType(fieldTuple[1]);
field.setWidth(Integer.parseInt(fieldTuple[2]));
headers.add(fieldTuple[0]);
fieldWidth.add(Integer.parseInt(fieldTuple[2]));
if (field.getType() == FIELD_TYPE.DATE) {
if (fieldTuple.length > 3) {
field.setDateFormat(fieldTuple[3].replace("\"", ""));
} else {
logger.error("Date format is missing for the field {}", field.getName());
throw new RuntimeException("Missing date format");
}
}
fields.add(field);
}
header = headers.toArray(new String[headers.size()]);
int[] width = Ints.toArray(fieldWidth);
FixedWidthFields lengths = new FixedWidthFields(header, width);
FixedWidthParserSettings settings = new FixedWidthParserSettings(lengths);
settings.getFormat().setPadding(this.padding);
fixedWidthParser = new FixedWidthParser(settings);
}
示例4: createParser
import com.univocity.parsers.fixed.FixedWidthParser; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected FixedWidthParser createParser(FixedWidthParserSettings settings) {
return new FixedWidthParser(settings);
}