From b18db5fccb955d72e29d849b2a797dd3d914d1f6 Mon Sep 17 00:00:00 2001 From: Kohei Tamura Date: Fri, 3 Mar 2017 14:29:03 +0900 Subject: [PATCH] Work around the issue #9, FileNotFoundException on Jetty * Windows --- .../troubles/UnrestrictedUploadServlet.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/t246osslab/easybuggy/troubles/UnrestrictedUploadServlet.java b/src/main/java/org/t246osslab/easybuggy/troubles/UnrestrictedUploadServlet.java index 3ba09603..2d29ab59 100644 --- a/src/main/java/org/t246osslab/easybuggy/troubles/UnrestrictedUploadServlet.java +++ b/src/main/java/org/t246osslab/easybuggy/troubles/UnrestrictedUploadServlet.java @@ -3,6 +3,7 @@ import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -10,7 +11,6 @@ import java.util.Locale; import javax.imageio.ImageIO; - import javax.servlet.ServletException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; @@ -80,12 +80,17 @@ protected void doPost(HttpServletRequest req, HttpServletResponse res) throws Se if (fileName == null || fileName.equals("")) { doGet(req, res); } - out = new FileOutputStream(savePath + File.separator + fileName); - in = filePart.getInputStream(); - int read = 0; - final byte[] bytes = new byte[1024]; - while ((read = in.read(bytes)) != -1) { - out.write(bytes, 0, read); + // TODO Remove this try block that is a workaround of issue #9 (FileNotFoundException on Jetty * Windows) + try { + out = new FileOutputStream(savePath + File.separator + fileName); + in = filePart.getInputStream(); + int read = 0; + final byte[] bytes = new byte[1024]; + while ((read = in.read(bytes)) != -1) { + out.write(bytes, 0, read); + } + } catch (FileNotFoundException e) { + // Ignore because file already exists } boolean isConverted = true;