/** * This must be called to release the lock */ void release() { IOUtil.shutdownStream(fileOutputStream); if (lockFile != null) { //noinspection ResultOfMethodCallIgnored lockFile.delete(); } fileOutputStream = null; lockFile = null; } }
/** * Get the contents of a <code>Reader</code> as a String. */ public static String toString(final Reader input) throws IOException { return toString(input, DEFAULT_BUFFER_SIZE); }
/** * Serialize chars from a <code>String</code> to bytes on an <code>OutputStream</code>, and * flush the <code>OutputStream</code>. */ public static void copy(final String input, final OutputStream output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); }
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); } }
private String getDesc(final File patchFile) { try { StringWriter sw = new StringWriter(); FileReader fr = new FileReader(patchFile); IOUtil.copy(fr, sw); IOUtil.shutdownReader(fr); return sw.toString(); } catch (FileNotFoundException e) { final String message = "Could not find patch file : " + patchFile; log.error(message, e); return message; } catch (IOException e) { final String message = "Could not read patch file : " + patchFile; log.error(message, e); return message; } }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. */ public static byte[] toByteArray(final InputStream input) throws IOException { return toByteArray(input, DEFAULT_BUFFER_SIZE); }
/** * Get the contents of a <code>String</code> as a <code>byte[]</code>. */ public static byte[] toByteArray(final String input) throws IOException { return toByteArray(input, DEFAULT_BUFFER_SIZE); }
/** * Get the contents of a <code>byte[]</code> as a String. * The platform's default encoding is used for the byte-to-char conversion. */ public static String toString(final byte[] input) throws IOException { return toString(input, DEFAULT_BUFFER_SIZE); }
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; }
/** * Copy and convert bytes from a <code>byte[]</code> to chars on a * <code>Writer</code>. * The platform's default encoding is used for the byte-to-char conversion. */ public static void copy(final byte[] input, final Writer output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code>. */ public static byte[] toByteArray(final Reader input) throws IOException { return toByteArray(input, DEFAULT_BUFFER_SIZE); }
/** * Get the contents of an <code>InputStream</code> as a String. * The platform's default encoding is used for the byte-to-char conversion. */ public static String toString(final InputStream input) throws IOException { return toString(input, DEFAULT_BUFFER_SIZE); }
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; }
/** * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>. */ public static void copy(final InputStream input, final OutputStream output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); }
/** * Get the contents of an <code>InputStream</code> as a String. * @param encoding The name of a supported character encoding. See the * <a href="http://www.iana.org/assignments/character-sets">IANA * Charset Registry</a> for a list of valid encoding types. */ public static String toString(final InputStream input, final String encoding) throws IOException { return toString(input, encoding, DEFAULT_BUFFER_SIZE); }
@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; } }
/** * Copy and convert bytes from an <code>InputStream</code> to chars on a * <code>Writer</code>. * The platform's default encoding is used for the byte-to-char conversion. */ public static void copy(final InputStream input, final Writer output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); }
/** * Get the contents of a <code>byte[]</code> as a String. * @param encoding The name of a supported character encoding. See the * <a href="http://www.iana.org/assignments/character-sets">IANA * Charset Registry</a> for a list of valid encoding types. */ public static String toString(final byte[] input, final String encoding) throws IOException { return toString(input, encoding, DEFAULT_BUFFER_SIZE); }
/** * 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; }