Skip to content

Commit

Permalink
Work around the issue #9, FileNotFoundException on Jetty * Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tamura committed Mar 3, 2017
1 parent ec67c3c commit b18db5f
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
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;
import java.io.OutputStream;
import java.util.Locale;

import javax.imageio.ImageIO;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b18db5f

Please sign in to comment.