how to configure FlatFileItemWriter to output the file to a ByteArrayRecource?



I have a situation in which the deployment server doesn’t allow the application to output files to its file system … so what i’m trying to do is to configure the FlatFileItemWriter to output the result file to a static Resource property (multi Threading is not an issue here ) . the current code i have is

...
flatFileItemWriter.setResource(new FileSystemResource("outputBatch/users.csv"));
...

is there any way i can output this file to a static Resource property to be accessed later, for example ByteArrayResource or InMemoryResource . thanks in advance

Answer

The FlatFileItemWriter is designed to write items to a flat file or a writable Resource that represents a file. Here is an excerpt from its Javadoc:

The location of the output file is defined by a Resource and must represent a writable file.

So in your case, you need to use a custom writer that writes items to an in-memory resource.



Source: stackoverflow