2

I have a Spring boot app, and I wrote some ItemWriter and ItemReaders, for example for JSON files and CSV files.

I want to add a step of compressing to GZIP and decompressing from GZIP.

I wanted to know if it is possible to do as usual with JavaStreams -

If I have some InputStream or OutputStream, I can decorate it with another stream (i.e., another stream can get it in it's constructor and use it), and that way to get all of the streams' functionality easily.

Can it be done with the Spring ItemWriter and ItemReader?

Else, what's the best way to add compressing and decompressing to an existing writers and readers?

ChikChak
  • 936
  • 19
  • 44
  • Its is not spring, but perhaps give a library I wrote a spin: https://github.com/skjolber/unzip-csv – ThomasRS Jan 12 '20 at 21:27
  • @ThomasRS I don't use only CSV but also JSONs.. – ChikChak Jan 12 '20 at 21:40
  • The library is easily extendable to using JSONs. – ThomasRS Jan 13 '20 at 23:08
  • @ThomasRS Still, I'd prefer to use a native Spring solution – ChikChak Jan 14 '20 at 05:54
  • 2
    Where is your [MCVE](https://stackoverflow.com/help/mcve)? I see no sample code which I can just copy, compile and run. Are you really expecting everyone to try and magically guess how you use those readers and writers? Apart from that, have you tried [`GZIPInputStream`](https://docs.oracle.com/javase/8/docs/api/java/util/zip/GZIPInputStream.html) and [`GZIPOutputStream`](https://docs.oracle.com/javase/8/docs/api/java/util/zip/GZIPOutputStream.html)? – kriegaex Jan 18 '20 at 06:03

1 Answers1

1

Given that there are no other answers yet...let me propose a solution...

It won't be that hard to employ the Decorator Pattern to have the output/input compressed or decompressed in a ItemWriter and ItemReader, respectivly. The restartability of the jobs that use those decorated ItemWriter and ItemReader, however, may be compromised.

...what's the best way to add compressing and decompressing to an existing writers and readers?

I'd suggest a separate step - a TaskletStep - with a Tasklet to do just the compression/decompression.

gears
  • 690
  • 3
  • 6