spring-projects / spring-batch-extensions

Spring Batch Extensions
242 stars 258 forks source link

Make it possible to read FileSystemResource in PoiItemReader #35

Closed haansuk closed 3 years ago

haansuk commented 7 years ago

This is the solution to the issue #34

To read excel file resources using FileSystemResource, remove unnecessary validation check in PoiItemReader.openExcelFile method

if (!workbookStream.markSupported() && !(workbookStream instanceof PushbackInputStream)) {
    throw new IllegalStateException("InputStream MUST either support mark/reset, or be wrapped as a PushbackInputStream");
}

Validation check is unnecessary because WorkbookFactory.create(workbookStream) method wrap InputStream as PushBackInputStream when that InputStream isn’t marksupported

if(!((InputStream)inp).markSupported()) {
    inp = new PushbackInputStream((InputStream)inp, 8);
}

So after removing unnecessary validation check, I tested PoiItemReader.openExcelFile method by putting FileSystemResource as a parameter value and check it perfectly works.

@mminella , @mdeinum please check my pull request

mdeinum commented 3 years ago

Fixed in #65.