简体   繁体   中英

How to write to a compressed file in spring-batch

I'm investigating using spring batch for importing and exporting data between flat files and a database. I know what I'm trying to do is going to be easy, but I cannot for the life of me figure out how to do it. What I'm trying to do is have data read from the database and written to a compressed file. Note, I don't want to write all of the data to an uncompressed file and then run a further step to compress this. I need to write the compressed file as the only output of the process.

In my head I got a pipeline image in my head, which may be blinding me to the batch way of doing this. Should I be creating a custom ZippedFileItemWriter? How do I chain a FlatFileItemWriter and a Zipping version together? Is there some other mechanism that's better suited to this?

Any pointers would be gratefully received. I'm a little surprised that this isn't something that would be part of the core framework; it doesn't appear to be such a mad idea. Maybe it is and I'm just missing it.

Regards,

mipper

I agree with Matthias' answer but I think 1-step solution is not restartable. Do you have some requirements of restartability? Look at append-to-a-compressed-stream

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM