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