From 17990c7bf49df3014c0859cc006ccf63ea2396a8 Mon Sep 17 00:00:00 2001 From: kimjihun Date: Thu, 8 Aug 2024 18:14:42 +0900 Subject: [PATCH] =?UTF-8?q?*=20=EB=B0=B0=EC=B9=98=20=EC=A2=85=EB=A3=8C=20?= =?UTF-8?q?=ED=9B=84=20=EC=97=91=EC=85=80=20=ED=8C=8C=EC=9D=BC=20=EA=B9=A8?= =?UTF-8?q?=EC=A7=90=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0=20close=20#?= =?UTF-8?q?8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/springbatch/batch/ExcelRowWriter.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/springbatch/batch/ExcelRowWriter.java b/src/main/java/com/example/springbatch/batch/ExcelRowWriter.java index 8d5e363..5433940 100644 --- a/src/main/java/com/example/springbatch/batch/ExcelRowWriter.java +++ b/src/main/java/com/example/springbatch/batch/ExcelRowWriter.java @@ -19,11 +19,13 @@ public class ExcelRowWriter implements ItemStreamWriter { 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 { @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 { workbook.close(); } catch (IOException e) { throw new ItemStreamException(e); + } finally { + isClosed = true; } } }