* 배치 종료 후 엑셀 파일 깨짐 문제 해결 close #8

This commit is contained in:
kimjihun
2024-08-08 18:14:42 +09:00
parent 87dea6017a
commit 17990c7bf4

View File

@@ -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;
}
}
}