文件编码中面临的问题-使用文件到字符串转换器的UTF-8 / 16

时间:2018-09-17 14:49:05

标签: spring spring-boot spring-integration spring-integration-sftp spring-integration-aws

在spring Integration AWS应用程序中,使用s3-outbound-gateway将文件从源文件夹路由到目标S3存储桶。想要使用file-to-string-transformer对文件UTF-8 / 16进行编码并上传到目标存储区中。但是放置在目标存储桶中的输出文件未进行编码,应用程序也不会引发错误。

这里是否还有任何遗漏以及实现此目的的其他方法?

 <file:file-to-string-transformer input-channel="fileswithoutencoding" output-channel="filesOutS3Transformer" charset="UTF-8"/>
      <!-- added this line -->
<integration:transformer input-channel="filesOutS3Transformer" output-channel="filesS3GateWay" expression="payload.bytes" />
    <int-aws:s3-outbound-gateway id="s3File"
            request-channel="filesS3GateWay"
            reply-channel="filesS3ChainChannel"
            transfer-manager="transferManager"
            bucket-expression = "headers.TARGET_PATH"
            key-expression="headers.file_name"
            command="UPLOAD">
            <int-aws:request-handler-advice-chain>
                <ref bean="retryAdvice" />
            </int-aws:request-handler-advice-chain>
        </int-aws:s3-outbound-gateway>

路由到本地文件: 尽管字符集为8/16/32,但仅使用文件到字符串的转换器将文件编码为UTF-8格式。

<integration:chain id="filesOutChain" input-channel="filesOut">
    <integration:transformer expression="headers.FILE"/>
    <file:file-to-string-transformer charset="UTF-16"/>
<!-- though bytes conversion is not required,just added for testing purpose -->
    <integration:transformer expression="payload.bytes"/>
        <file:outbound-gateway id="fileMover" 
            auto-create-directory="true"
            directory-expression="headers.TARGET_PATH"
            mode="REPLACE">
            <file:request-handler-advice-chain>
                <ref bean="retryAdvice" />
            </file:request-handler-advice-chain>
        </file:outbound-gateway>    
        <integration:gateway request-channel="filesOutChainChannel" error-channel="errorChannel"/>
    </integration:chain>

0 个答案:

没有答案