Tabnine Logo
IOUtil
Code IndexAdd Tabnine to your IDE (free)

How to use
IOUtil
in
com.atlassian.jira.util

Best Java code snippets using com.atlassian.jira.util.IOUtil (Showing top 20 results out of 315)

origin: com.atlassian.jira/jira-core

  /**
   * This must be called to release the lock
   */
  void release()
  {
    IOUtil.shutdownStream(fileOutputStream);
    if (lockFile != null) {
      //noinspection ResultOfMethodCallIgnored
      lockFile.delete();
    }
    fileOutputStream = null;
    lockFile = null;
  }
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

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);
  }
}
origin: com.atlassian.jira/jira-core

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;
  }
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

IOUtil.shutdownWriter(pw);
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

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;
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

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;
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-configurator

  @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;
  }
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
}
origin: com.atlassian.jira/jira-core

/**
 * 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;
}
com.atlassian.jira.utilIOUtil

Javadoc

General IO Stream manipulation.

This class provides static utility methods for input/output operations, particularly buffered copying between sources (InputStream, Reader, String and byte[]) and destinations (OutputStream, Writer, String and byte[]).

Unless otherwise noted, these copy methods do not flush or close the streams. Often, doing so would require making non-portable assumptions about the streams' origin and further use. This means that both streams' close() methods must be called after copying. if one omits this step, then the stream resources (sockets, file descriptors) are released when the associated Stream is garbage-collected. It is not a good idea to rely on this mechanism. For a good overview of the distinction between "memory management" and "resource management", see this UnixReview article

For each copy method, a variant is provided that allows the caller to specify the buffer size (the default is 4k). As the buffer size can have a fairly large impact on speed, this may be worth tweaking. Often "large buffer -> faster" does not hold, even for large data transfers.

For byte-to-char methods, a copy variant allows the encoding to be selected (otherwise the platform default is used).

The copy methods use an internal buffer when copying. It is therefore advisable not to deliberately wrap the stream arguments to the copy methods in Buffered* streams. For example, don't do the following:

copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) );

The rationale is as follows:

Imagine that an InputStream's read() is a very expensive operation, which would usually suggest wrapping in a BufferedInputStream. The BufferedInputStream works by issuing infrequent java.io.InputStream#read(byte[] b,int off,int len) requests on the underlying InputStream, to fill an internal buffer, from which further read requests can inexpensively get their data (until the buffer runs out).

However, the copy methods do the same thing, keeping an internal buffer, populated by InputStream#read(byte[] b,int off,int len) requests. Having two buffers (or three if the destination stream is also buffered) is pointless, and the unnecessary buffer management hurts performance slightly (about 3%, according to some simple experiments).

Most used methods

  • shutdownStream
    Unconditionally close an OutputStream. Equivalent to OutputStream#close(), except any exceptions wil
  • toString
    Get the contents of a byte[] as a String.
  • copy
    Copy and convert bytes from a byte[] to chars on aWriter, using the specified encoding.
  • shutdownReader
    Unconditionally close an Reader. Equivalent to Reader#close(), except any exceptions will be ignored
  • shutdownWriter
    Unconditionally close an Writer. Equivalent to Writer#close(), except any exceptions will be ignored
  • toByteArray
    Get the contents of a String as a byte[].

Popular in Java

  • Reading from database using SQL prepared statement
  • putExtra (Intent)
  • startActivity (Activity)
  • setScale (BigDecimal)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Kernel (java.awt.image)
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Collectors (java.util.stream)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now