* 배치 종료 후 엑셀 파일 깨짐 문제 해결 close #8
This commit is contained in:
@@ -19,11 +19,13 @@ public class ExcelRowWriter implements ItemStreamWriter<BeforeEntity> {
|
||||
private Workbook workbook;
|
||||
private Sheet sheet;
|
||||
private int currentRowNumber;
|
||||
private boolean isClosed;
|
||||
|
||||
public ExcelRowWriter(String filePath) throws IOException {
|
||||
|
||||
this.filePath = filePath;
|
||||
currentRowNumber = 0;
|
||||
this.isClosed = false;
|
||||
this.currentRowNumber = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +45,10 @@ public class ExcelRowWriter implements ItemStreamWriter<BeforeEntity> {
|
||||
@Override
|
||||
public void close() throws ItemStreamException {
|
||||
|
||||
if (isClosed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
|
||||
workbook.write(fileOut);
|
||||
} catch (IOException e) {
|
||||
@@ -52,6 +58,8 @@ public class ExcelRowWriter implements ItemStreamWriter<BeforeEntity> {
|
||||
workbook.close();
|
||||
} catch (IOException e) {
|
||||
throw new ItemStreamException(e);
|
||||
} finally {
|
||||
isClosed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user