评论需要 reader.markSupported() 到 return true beanio
Comments require reader.markSupported() to return true beanio
Xml 文件
<beanio xmlns="http://www.beanio.org/2012/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
<stream name="stream" format="delimited" ignoreUnidentifiedRecords="true">
<parser>
<property name="delimiter" value="|"/>
<property name="comments" value="Response Codes:,|File Trailer|,File Header|"/>
</parser>
<group name="HeaderRecord">
<record>
.
.
.
</record>
</group>
<group name="GroupHeader">
<record>
.
.
.
.
</record>
</group>
</stream>
</beanio>
包含记录的文件如下所示
1 File Header|
. HeaderRecord text.....
. GroupHeader text......
19 Response Codes:
20 |A - Whosebug |
21 |B - Facebook |
22 |C - Google |
23 |File Trailer|
Error
java.lang.IllegalArgumentException: Comments require reader.markSupported() to return true
at org.beanio.stream.util.CommentReader.<init>(CommentReader.java:61)
at org.beanio.stream.delimited.DelimitedReader.<init>(DelimitedReader.java:149)
at org.beanio.stream.delimited.DelimitedRecordParserFactory.createReader(DelimitedRecordParserFactory.java:56)
at org.beanio.internal.parser.StreamFormatSupport.createRecordReader(StreamFormatSupport.java:61)
at org.beanio.internal.parser.Stream.createBeanReader(Stream.java:88)
我想忽略文件头、尾部和响应代码。响应代码从下一行开始。建议在 属性 中发表评论的各种博客。谁能解释为什么它不起作用?
问题出在您用来从中读取数据的 Reader
实现,如错误消息所示:
java.lang.IllegalArgumentException: Comments require
reader.markSupported() to return true
您需要使用支持缓冲的 Reader
,即实现 mark()
和 reset()
方法的 Reader
。请参阅文档的 section 4.1.2 以及 comments
属性 名称的描述和解释,其中指出:
A comma separated list of values for identifying commented lines. If a
line read from an input stream begins with any of the configured
values, the line is ignored. A backslash may be used to escape a comma
and itself. All whitespace is preserved.
Enabling comments require the input reader passed to StreamFactory to
support marking. Among others, Java's BufferedReader and StringReader
support marking.
要使注释生效,您需要使用 BufferedReader
或 StringReader
读取数据
InputStream inputStream = ... // obtain some input stream to the source of your data
Reader reader = new BufferedReader(new InputStreamReader(inputStream));
BeanReader beanReader = factory.createReader("streamName", reader);
Xml 文件
<beanio xmlns="http://www.beanio.org/2012/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
<stream name="stream" format="delimited" ignoreUnidentifiedRecords="true">
<parser>
<property name="delimiter" value="|"/>
<property name="comments" value="Response Codes:,|File Trailer|,File Header|"/>
</parser>
<group name="HeaderRecord">
<record>
.
.
.
</record>
</group>
<group name="GroupHeader">
<record>
.
.
.
.
</record>
</group>
</stream>
</beanio>
包含记录的文件如下所示
1 File Header|
. HeaderRecord text.....
. GroupHeader text......
19 Response Codes:
20 |A - Whosebug |
21 |B - Facebook |
22 |C - Google |
23 |File Trailer|
Error
java.lang.IllegalArgumentException: Comments require reader.markSupported() to return true
at org.beanio.stream.util.CommentReader.<init>(CommentReader.java:61)
at org.beanio.stream.delimited.DelimitedReader.<init>(DelimitedReader.java:149)
at org.beanio.stream.delimited.DelimitedRecordParserFactory.createReader(DelimitedRecordParserFactory.java:56)
at org.beanio.internal.parser.StreamFormatSupport.createRecordReader(StreamFormatSupport.java:61)
at org.beanio.internal.parser.Stream.createBeanReader(Stream.java:88)
我想忽略文件头、尾部和响应代码。响应代码从下一行开始。建议在 属性 中发表评论的各种博客。谁能解释为什么它不起作用?
问题出在您用来从中读取数据的 Reader
实现,如错误消息所示:
java.lang.IllegalArgumentException: Comments require reader.markSupported() to return true
您需要使用支持缓冲的 Reader
,即实现 mark()
和 reset()
方法的 Reader
。请参阅文档的 section 4.1.2 以及 comments
属性 名称的描述和解释,其中指出:
A comma separated list of values for identifying commented lines. If a line read from an input stream begins with any of the configured values, the line is ignored. A backslash may be used to escape a comma and itself. All whitespace is preserved.
Enabling comments require the input reader passed to StreamFactory to support marking. Among others, Java's BufferedReader and StringReader support marking.
要使注释生效,您需要使用 BufferedReader
或 StringReader
InputStream inputStream = ... // obtain some input stream to the source of your data
Reader reader = new BufferedReader(new InputStreamReader(inputStream));
BeanReader beanReader = factory.createReader("streamName", reader);