Java 如何使用BeanWriter创建分隔文件

Java 如何使用BeanWriter创建分隔文件,java,apache-camel,bean-io,Java,Apache Camel,Bean Io,我可以创建文件,但输出文件不包含分隔符,它具有fixedlength分隔符。如何使用beanio json中提供的分隔符 下面是我尝试编写该文件的代码,但它没有给出预期的输出 String qualifiedChannelName = programId + "_" + channel; BeanWriter out = factory.createWriter(qualifiedChannelName, new File("D:\\dataengine\\files\\40287a3

我可以创建文件,但输出文件不包含分隔符,它具有fixedlength分隔符。如何使用beanio json中提供的分隔符

下面是我尝试编写该文件的代码,但它没有给出预期的输出

String qualifiedChannelName = programId + "_" + channel;

    BeanWriter out = factory.createWriter(qualifiedChannelName, new File("D:\\dataengine\\files\\40287a35725ae63e0172934c765d0014\\tm.txt"));

    for (Transaction e : transactions) {
        out.write(e);
    }
    out.flush();
    out.close();
这是我的BeanIO文件格式

[ { \"key\": \"beanio.transaction.sku.streamname\", \"value\": \"SKU\" }, { \"key\": \"beanio.transaction.payment.streamname\", \"value\": \"PAYMENT\" }, { \"key\": \"transaction.payment.identifier\", \"value\": \"12\" }, { \"key\": \"transaction.sku.identifier\", \"value\": \"11\" }, { \"key\": \"create.ghost.customer.from.card\", \"value\": \"true\" }, { \"key\": \"beanio.fileHeadercustomer.streamname\", \"value\": \"Header\" }, { \"key\": \"tenant.useHeader\", \"value\": \"false\" }, { \"key\": \"beanio.fileHeaderTransaction.streamname\", \"value\": \"Header\" }, { \"key\": \"transaction.fileheader.identifier\", \"value\": \"00\" }, { \"key\": \"beanio.card.streamname\", \"value\": \"Card\" }, { \"key\": \"customer.record.identifier\", \"value\": \"10\" }, { \"key\": \"beanio.transaction.streamname\", \"value\": \"Transaction\" }, { \"key\": \"card.fileheader.identifier\", \"value\": \"00\" }, { \"key\": \"customer.fileheader.identifier\", \"value\": \"00\" }, { \"key\": \"beanio.account.streamname\", \"value\": \"\" }, { \"key\": \"beanio.configuration\", \"value\": \"\\u003C?xml version=\\\"1.0\\\"?> <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=\\\"40287a35725ae63e0172934c765d0014_AJIO_ONLINE\\\" format=\\\"delimited\\\"> <parser class=\\\"com.loylty.dataacquisition.util.CustomDelimitedBeanIOParserFactory\\\"> <property name=\\\"customDelimiter\\\" value=\\\"\\\\\\\\^\\\"><\\/property> <\\/parser> <typeHandler type=\\\"java.util.Date\\\" class=\\\"com.loylty.dataacquisition.util.CustomDateTypeHandler\\\"> <property name=\\\"pattern\\\" value=\\\"dd-MMM-yyyy\\\"/> <\\/typeHandler> <typeHandler type=\\\"java.math.BigDecimal\\\" class=\\\"com.loylty.dataacquisition.util.BigDecimalHandler\\\"/> <typeHandler name=\\\"negativeHandler\\\" class=\\\"com.loylty.dataacquisition.util.NegativeBigDecimalHandler\\\"/> <record name=\\\"Transaction\\\" class=\\\"com.loylty.dataacquisition.entities.Transaction\\\" maxLength=\\\"17\\\" minLength=\\\"17\\\" > <field name=\\\"paymentProcessor\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"merchantName\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"merchantTransactionId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"terminalId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"merchantId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"terminalOwnerName\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"first6DigitCard\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"last4DigitCard\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"cardTypeCode\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"cardIssuer\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"acquirerId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionType\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionAmount\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionDate\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionTime\\\" regex=\\\"([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"postDate\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <\\/record> <\\/stream> <stream name=\\\"40287a35725ae63e0172934c765d0014_AJIO_ONLINE_REFUND\\\" format=\\\"delimited\\\"> <parser class=\\\"com.loylty.dataacquisition.util.CustomDelimitedBeanIOParserFactory\\\"> <property name=\\\"customDelimiter\\\" value=\\\"\\\\\\\\^\\\"><\\/property> <\\/parser> <typeHandler type=\\\"java.util.Date\\\" class=\\\"com.loylty.dataacquisition.util.CustomDateTypeHandler\\\"> <property name=\\\"pattern\\\" value=\\\"dd-MMM-yyyy\\\"/> <\\/typeHandler> <typeHandler type=\\\"java.math.BigDecimal\\\" class=\\\"com.loylty.dataacquisition.util.BigDecimalHandler\\\"/> <typeHandler name=\\\"negativeHandler\\\" class=\\\"com.loylty.dataacquisition.util.NegativeBigDecimalHandler\\\"/> <record name=\\\"Transaction\\\" class=\\\"com.loylty.dataacquisition.entities.Transaction\\\" maxLength=\\\"17\\\" minLength=\\\"17\\\" > <field name=\\\"paymentProcessor\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"merchantName\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"merchantTransactionId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"terminalId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"merchantId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"terminalOwnerName\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"first6DigitCard\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"last4DigitCard\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"cardTypeCode\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"cardIssuer\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"acquirerId\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionType\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionAmount\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionDate\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"transactionTime\\\" regex=\\\"([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <field name=\\\"postDate\\\" trim=\\\"true\\\" lazy=\\\"true\\\" maxLength=\\\"100\\\" /> <\\/record> <\\/stream> <\\/beanio>\\r\\n\" }, { \"key\": \"beanio.fileHeaderaccount.streamname\", \"value\": \"\" }, { \"key\": \"account.fileheader.identifier\", \"value\": \"00\" }, { \"key\": \"beanio.customer.streamname\", \"value\": \"Customer\" }, { \"key\": \"account.record.identifier\", \"value\": \"11\" }, { \"key\": \"card.record.identifier\", \"value\": \"12\" }, { \"key\": \"camel.routes\", \"value\": \"\\u003C?xml version=\\\"1.0\\\"?> <routes xmlns=\\\"http://camel.apache.org/schema/spring\\\"> <route startupOrder=\\\"1\\\" id=\\\"download\\\" autoStartup=\\\"false\\\"> <from uri=\\\"sftp://lradmin@192.168.250.204:22/../../../../files/40287a35725ae63e0172934c765d0014/sftp?password=Lrp@1234&amp;sendEmptyMessageWhenIdle=true&amp;move=.done&amp;delay=15000&amp;readLock=readLockCheckInterval&amp;disconnectOnBatchComplete=true\\\" /> <choice> <when> <simple>${header.CamelFileNameOnly} == null<\\/simple> <\\/when> <otherwise> <to uri =\\\"file:/dataengine/files/40287a35725ae63e0172934c765d0014\\\" /> <\\/otherwise> <\\/choice> <onCompletion> <filter> <log message=\\\"download thread completed\\\"><\\/log> <simple>${property.CamelBatchComplete} == true<\\/simple> <to uri=\\\"direct:completeddownload\\\"/> <\\/filter> <\\/onCompletion> <\\/route> <route id=\\\"handback\\\" autoStartup=\\\"false\\\"> <from uri =\\\"file:/dataengine/files/40287a35725ae63e0172934c765d0014?include=.*\\\\.handback&amp;delay=15000&amp;sendEmptyMessageWhenIdle=true\\\" /> <choice> <when> <simple>${body} == null<\\/simple> <\\/when> <otherwise> <to uri=\\\"sftp://lradmin@192.168.250.204:22/../../files/40287a35725ae63e0172934c765d0014/handback?password=Lrp@1234&amp;sendEmptyMessageWhenIdle=true&amp;disconnectOnBatchComplete=true\\\" /> <\\/otherwise> <\\/choice> <onCompletion> <filter> <log message=\\\"HandBack thread completed\\\"><\\/log> <simple>${property.CamelBatchComplete} == true<\\/simple> <to uri=\\\"direct:completedhandback\\\"/> <\\/filter> <\\/onCompletion> <\\/route> <route> <from uri=\\\"direct:completeddownload\\\" /> <to uri=\\\"controlbus:route?routeId=download&amp;action=stop&amp;async=true\\\" /> <\\/route> <route> <from uri=\\\"direct:completedhandback\\\" /> <to uri=\\\"controlbus:route?routeId=handback&amp;action=stop&amp;async=true\\\" /> <\\/route> <route startupOrder=\\\"2\\\" id=\\\"AJIO_ONLINE\\\" autoStartup=\\\"false\\\"> <from uri=\\\"file:/dataengine/files/40287a35725ae63e0172934c765d0014/?include=POS.*\\\\.txt&amp;sendEmptyMessageWhenIdle=true&amp;delay=5000&amp;sortBy=date:file:yyyyMMdd;file:name\\\"/> <onCompletion> <filter> <simple>${property.CamelBatchComplete} == true<\\/simple> <to uri=\\\"direct:completedAJIO_ONLINE\\\"/> <\\/filter> <\\/onCompletion> <setHeader headerName=\\\"fileType\\\"> <simple>TRANSACTION<\\/simple> <\\/setHeader> <setheader headerName=\\\"channel\\\"> <simple>AJIO_ONLINE<\\/simple> <\\/setheader> <setHeader headerName=\\\"programId\\\"> <simple>40287a35725ae63e0172934c765d0014<\\/simple> <\\/setHeader> <to uri=\\\"bean:genericFileProcessorImpl?method=processOnlinePartner\\\"/> <\\/route> <route> <from uri=\\\"direct:completedAJIO_ONLINE\\\" /> <to uri=\\\"controlbus:route?routeId=AJIO_ONLINE&amp;action=stop&amp;async=true\\\" /> <\\/route> <route startupOrder=\\\"3\\\" id=\\\"AJIO_ONLINE_REFUND\\\" autoStartup=\\\"false\\\"> <from uri=\\\"file:/dataengine/files/40287a35725ae63e0172934c765d0014/?include=refundpos.*\\\\.txt&amp;sendEmptyMessageWhenIdle=true&amp;delay=5000&amp;sortBy=date:file:yyyyMMdd;file:name\\\"/> <onCompletion> <filter> <simple>${property.CamelBatchComplete} == true<\\/simple> <to uri=\\\"direct:completedAJIO_ONLINE_REFUND\\\"/> <\\/filter> <\\/onCompletion> <setHeader headerName=\\\"fileType\\\"> <simple>REFUND<\\/simple> <\\/setHeader> <setheader headerName=\\\"channel\\\"> <simple>AJIO_ONLINE_REFUND<\\/simple> <\\/setheader> <setHeader headerName=\\\"programId\\\"> <simple>40287a35725ae63e0172934c765d0014<\\/simple> <\\/setHeader> <to uri=\\\"bean:genericFileProcessorImpl?method=processOnlinePartner\\\"/> <\\/route> <route> <from uri=\\\"direct:completedAJIO_ONLINE_REFUND\\\" /> <to uri=\\\"controlbus:route?routeId=AJIO_ONLINE_REFUND&amp;action=stop&amp;async=true\\\" /> <\\/route> <\\/routes>\" }, { \"key\": \"create.ghost.account.from.card\", \"value\": \"true\" }, { \"key\": \"beanio.fileHeadercard.streamname\", \"value\": \"\" }, { \"key\": \"transaction.record.identifier\", \"value\": \"10\" } ]
预期产出

BILLDESK    RUR28350404633  AJIO    pay_sp_4a7caa2b-28bf-11ea-83ae-f1c5f19c7fb3 BDR00001    0000000BDR00001 AJIO    324145  4164    SALE    1401.0  24-Mar-2020 13:58:52    
BILLDESK^RUR28350404633^AJIO^pay_sp_4a7caa2b-28bf-11ea-83ae-f1c5f19c7fb3^BDR00001^0000000BDR00001^AJIO^324145^4164^SALE^1401.0^24-Mar-2020^13:58:52^

我不知道你为什么需要为BeanIO定制解析器


尝试使用以下命令配置默认解析器:


我不确定您为什么需要为BeanIO定制解析器


尝试使用以下命令配置默认解析器:



这是Apache Camel配置BeanIO的方式吗?通常会有注释或mapping.xml文件来配置BeanIO。我在您的配置中没有看到任何可能告诉BeanIO它是一种
分隔的
文件格式,而不是
固定长度的
格式。PS:您可能应该从帖子中删除任何敏感信息,如sftp服务器的位置和凭据。请查看我的最新编辑。添加了XML这是Apache Camel配置BeanIO的方式吗?通常会有注释或mapping.xml文件来配置BeanIO。我在您的配置中没有看到任何可能告诉BeanIO它是一种
分隔的
文件格式,而不是
固定长度的
格式。PS:您可能应该从帖子中删除任何敏感信息,如sftp服务器的位置和凭据。请查看我的最新编辑。添加了XMLWe有多个文件源,每个源中的分隔符可以是varyOk,让我们尝试缩小它的范围,然后,首先设置默认分隔符并检查它是否正常工作,然后,我们进一步讨论标准映射文件未完成的更改。您是否可以调试应用程序,然后检查是否调用了
CustomDelimitedBeanIOParserFactory
,并且工作正常?使用my
CustomDelimitedBeanIOParserFactory
它可以工作我们有多个文件源,并且可以从每个源使用分隔符varyOk,让我们尝试缩小范围,然后,首先设置默认分隔符并检查它是否正确工作,然后,我们进一步讨论标准映射文件未完成的更改。您是否可以调试应用程序,然后检查您的
CustomDelimitedBeanIOParserFactory
是否被调用并正常工作?使用my
CustomDelimitedBeanIOParserFactory
它可以工作
BILLDESK^RUR28350404633^AJIO^pay_sp_4a7caa2b-28bf-11ea-83ae-f1c5f19c7fb3^BDR00001^0000000BDR00001^AJIO^324145^4164^SALE^1401.0^24-Mar-2020^13:58:52^