Source:
<code>private File createFileFromAttachement(Attachment attachment, Response response) { InputStream inputStream = null; String filename; File newFile = null; filename = attachment.getContentDisposition().getParameter( FILENAME_CONTENT_DISPOSITION_PARAMETER_NAME); if (StringUtils.isEmpty(filename)) { logger.debug("Filename not found, using default."); filename = DEFAULT_FILE_NAME; } else { filename = FilenameUtils.getName(filename); logger.debug("Filename: {}", filename); } try { inputStream = attachment.getDataHandler().getInputStream(); if (inputStream != null && inputStream.available() == 0) { inputStream.reset(); } } catch (IOException e) { logger.warn("IOException reading stream from file attachment in multipart body", e); Response.ResponseBuilder responseBuilder = Response.serverError(); response = responseBuilder.build(); closeInputStream(inputStream); } if (filename.endsWith(JAR_EXT) || filename.endsWith(KAR_EXT)) { if (inputStream != null) { FileOutputStream outputStream = null; try { File uploadDir = new File(DEFAULT_FILE_LOCATION); if (!uploadDir.exists()) { uploadDir.mkdirs(); } newFile = new File(uploadDir, filename); newFile.createNewFile(); outputStream = new FileOutputStream(newFile); int read; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } outputStream.flush(); outputStream.close(); } catch (IOException e) { logger.warn("Unable to write file.", e); Response.ResponseBuilder responseBuilder = Response.serverError(); response = responseBuilder.build(); } finally { <START> try { <END> inputStream.close(); } catch (IOException e) { logger.warn("Unable to close the input file stream.", e); } if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.warn("Unable to close the output file stream.", e); } } } } else { logger.debug("No file attachment found"); Response.ResponseBuilder responseBuilder = Response.serverError(); response = responseBuilder.build(); closeInputStream(inputStream); } } else { logger.debug("Wrong file type."); Response.ResponseBuilder responseBuilder = Response.serverError(); responseBuilder.status(415); response = responseBuilder.build(); closeInputStream(inputStream); } return newFile; }</code><technical_language>IOUtils.closeQuietly()</technical_language>

Target:
private File createFileFromAttachement(Attachment attachment, Response response) { InputStream inputStream = null; String filename; File newFile = null; filename = attachment.getContentDisposition().getParameter( FILENAME_CONTENT_DISPOSITION_PARAMETER_NAME); if (StringUtils.isEmpty(filename)) { logger.debug("Filename not found, using default."); filename = DEFAULT_FILE_NAME; } else { filename = FilenameUtils.getName(filename); logger.debug("Filename: {}", filename); } try { inputStream = attachment.getDataHandler().getInputStream(); if (inputStream != null && inputStream.available() == 0) { inputStream.reset(); } } catch (IOException e) { logger.warn("IOException reading stream from file attachment in multipart body", e); Response.ResponseBuilder responseBuilder = Response.serverError(); response = responseBuilder.build(); IOUtils.closeQuietly(inputStream); } if (filename.endsWith(JAR_EXT) || filename.endsWith(KAR_EXT)) { if (inputStream != null) { try { File uploadDir = new File(DEFAULT_FILE_LOCATION); if (!uploadDir.exists()) { uploadDir.mkdirs(); } newFile = new File(uploadDir, filename); FileUtils.copyInputStreamToFile(inputStream, newFile); } catch (IOException e) { logger.warn("Unable to write file.", e); Response.ResponseBuilder responseBuilder = Response.serverError(); response = responseBuilder.build(); } finally { IOUtils.closeQuietly(inputStream); } } else { logger.debug("No file attachment found"); Response.ResponseBuilder responseBuilder = Response.serverError(); response = responseBuilder.build(); IOUtils.closeQuietly(inputStream); } } else { logger.debug("Wrong file type."); Response.ResponseBuilder responseBuilder = Response.serverError(); responseBuilder.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE_415); response = responseBuilder.build(); IOUtils.closeQuietly(inputStream); } return newFile; }