本文整理匯總了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);
}