/** * This must be called to release the lock */ void release() { IOUtil.shutdownStream(fileOutputStream); if (lockFile != null) { //noinspection ResultOfMethodCallIgnored lockFile.delete(); } fileOutputStream = null; lockFile = null; } }
private boolean writeZipResponse(final HttpServletResponse httpServletResponse, final InputStream inputStream) throws IOException { boolean bytesWritten = false; OutputStream out = httpServletResponse.getOutputStream(); byte[] buffer = new byte[4096]; try { while (true) { int bytesRead = inputStream.read(buffer); if (bytesRead == -1) { break; } out.write(buffer, 0, bytesRead); bytesWritten = true; } } finally { IOUtil.shutdownStream(inputStream); IOUtil.shutdownStream(out); } return bytesWritten; }
private Properties loadPropertiesFromLegacyFile(InputStream propertiesStream) { Properties props = new Properties(); if (propertiesStream != null) { try { props.load(propertiesStream); IOUtil.shutdownStream(propertiesStream); } catch (final IOException e) { log.warn("Failed to migrate custom default properties from '" + LEGACY_PROPERTIES_FILE + "' file. Please check the new admin configuration options added in " + "JIRA 4.4 to ensure your configuration is correct."); } } else { log.debug("No " + LEGACY_PROPERTIES_FILE + " file found to migrate, doing nothing."); } return props; }
@Nonnull @Override public KeyStore load(@Nonnull final CertificateDetails certificateDetails) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { final String fileName = certificateDetails.getKeyStoreLocation(); final String password = certificateDetails.getKeyStorePassword(); final KeyStore keyStore = KeyStore.getInstance("JKS"); final FileInputStream fileInputStream = new FileInputStream(fileName); try { keyStore.load(fileInputStream, password.length() == 0 ? null : password.toCharArray()); } finally { IOUtil.shutdownStream(fileInputStream); } return keyStore; } }
private void streamZipEntry(final ZipArchiveInputStream zipArchiveInputStream, final ZipArchiveEntry zipEntry) throws IOException { BufferedInputStream bufferedZipEntryInputStream = null; try { onZipEntryExists.consume(zipEntry); bufferedZipEntryInputStream = new BufferedInputStream(zipArchiveInputStream); IOUtil.copy(bufferedZipEntryInputStream, outputStream); } finally { IOUtil.shutdownStream(bufferedZipEntryInputStream); } }
/** * This will return a ZIP file that contains all the attachments of an issue. The file will be created in the * temporary directory and end in .zip * <p/> * you should delete the file when you are done, otherwise, well this is JIRA not Bamboo! * * @return a zip file containing all the attachments of an issue * @throws IOException if stuff goes wrong */ public File toZipFile(final Issue issue) throws IOException { final File zipFile = File.createTempFile(issue.getKey() + "-", ".zip"); final UniqueFileNameGenerator uniqueFileNameGenerator = new UniqueFileNameGenerator(); ZipArchiveOutputStream out = null; try { out = new ZipArchiveOutputStream(new FileOutputStream(zipFile)); copyAttachmentsToZipFile(issue, uniqueFileNameGenerator, out); } finally { IOUtil.shutdownStream(out); } return zipFile; }
/** * Sets the appropriate HTTP response headers on an attachment download response. Depending on the JIRA security * settings and the browser making the request, this can contain headers such as {@code Content-Disposition} and * {@code X-Download-Options} to force downloading rather than opening attachments. * * @param attachment the Attachment in play * @param userAgent the User-agent request header * @param httpServletResponse the attachment download response * @throws IOException if stuff goes wrong */ public void setAttachmentResponseHeaders(final Attachment attachment, final String userAgent, final HttpServletResponse httpServletResponse) throws IOException { String filename = attachment.getFilename(); BufferedInputStream inputStream = null; try { OpenAttachmentStrategy strategy = getOpenAttachmentStrategy(filename, attachment.getMimetype()); strategy.setResponseHeaders(httpServletResponse); } finally { if (inputStream != null) { IOUtil.shutdownStream(inputStream); } } }
final Avatar toCreate = AvatarImpl.createCustomAvatar(AVATAR_DEFAULT_BASE_FILENAME, contentType, project); Avatar createdAvatar = avatarManager.create(toCreate, bais, AvatarManager.ImageSize.LARGE.getOriginSelection()); IOUtil.shutdownStream(bais); final Long avatarId = createdAvatar.getId(); final com.atlassian.jira.bc.project.ProjectService.UpdateProjectValidationResult result = validateSetAvatar(user, project, avatarId);