Skip to content

Commit

Permalink
优化资源释放
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Dec 4, 2022
1 parent bf99a8b commit 40677b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public String[] getSupportFormat() {
public Flux<BoundedCell> read(InputStream inputStream, ExcelOption... options) {

return Flux.create(sink -> {
try {
Workbook wbs = WorkbookFactory.create(inputStream);
try (Workbook wbs = WorkbookFactory.create(inputStream)){
//获取sheets
int sheetSize = wbs.getNumberOfSheets();
for (int x = 0; x < sheetSize; x++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ private void handleWriteOption(Cell poiCell, WritableCell cell, Options... optio
}
}

static Comparator<WritableCell> comparator = Comparator
.comparing(WritableCell::getSheetIndex)
.thenComparing(WritableCell::getRowIndex)
.thenComparing(WritableCell::getColumnIndex);

@Override
public Mono<Void> write(Flux<WritableCell> dataStream,
OutputStream outputStream,
Expand All @@ -88,11 +93,7 @@ public Mono<Void> write(Flux<WritableCell> dataStream,
handleWriteOption(workbook, opts);

return dataStream
.sort(Comparator
.comparing(WritableCell::getSheetIndex)
.thenComparing(WritableCell::getRowIndex)
.thenComparing(WritableCell::getColumnIndex)
)
.sort(comparator)
.doOnNext(cell -> {
Sheet sheet;
Options cellOpts = cell instanceof OptionSupport ? ((OptionSupport) cell).options() : Options.empty();
Expand Down

0 comments on commit 40677b2

Please sign in to comment.