org.apache.commons.compress.utils

## Class IOUtils

- java.lang.Object
- - org.apache.commons.compress.utils.IOUtils

-     public final class IOUtils
      extends Object

  Utility functions

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `closeQuietly(Closeable c)` Closes the given Closeable and swallows any IOException that may occur.
    `static long` | `copy(InputStream input, OutputStream output)` Copies the content of a InputStream into an OutputStream.
    `static long` | `copy(InputStream input, OutputStream output, int buffersize)` Copies the content of a InputStream into an OutputStream
    `static int` | `readFully(InputStream input, byte[] b)` Reads as much from input as possible to fill the given array.
    `static int` | `readFully(InputStream input, byte[] b, int offset, int len)` Reads as much from input as possible to fill the given array with the given amount of bytes.
    `static long` | `skip(InputStream input, long numToSkip)` Skips the given number of bytes by repeatedly invoking skip on the given input stream if necessary.
    `static byte[]` | `toByteArray(InputStream input)` Gets the contents of an `InputStream` as a `byte[]`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### copy

          public static long copy(InputStream input,
                  OutputStream output)
                           throws IOException

      Copies the content of a InputStream into an OutputStream. Uses a default buffer size of 8024 bytes.
      Parameters:
        `input` - the InputStream to copy
        `output` - the target Stream
      Throws:
        `IOException` - if an error occurs

    - #### copy

          public static long copy(InputStream input,
                  OutputStream output,
                  int buffersize)
                           throws IOException

      Copies the content of a InputStream into an OutputStream
      Parameters:
        `input` - the InputStream to copy
        `output` - the target Stream
        `buffersize` - the buffer size to use
      Throws:
        `IOException` - if an error occurs

    - #### skip

          public static long skip(InputStream input,
                  long numToSkip)
                           throws IOException

      Skips the given number of bytes by repeatedly invoking skip on the given input stream if necessary.

      This method will only skip less than the requested number of bytes if the end of the input stream has been reached.

      Parameters:
        `input` - stream to skip bytes in
        `numToSkip` - the number of bytes to skip
      Returns:
        the number of bytes actually skipped
      Throws:
        `IOException`

    - #### readFully

          public static int readFully(InputStream input,
                      byte[] b)
                               throws IOException

      Reads as much from input as possible to fill the given array.

      This method may invoke read repeatedly to fill the array and only read less bytes than the length of the array if the end of the stream has been reached.

      Parameters:
        `input` - stream to read from
        `b` - buffer to fill
      Returns:
        the number of bytes actually read
      Throws:
        `IOException`

    - #### readFully

          public static int readFully(InputStream input,
                      byte[] b,
                      int offset,
                      int len)
                               throws IOException

      Reads as much from input as possible to fill the given array with the given amount of bytes.

      This method may invoke read repeatedly to read the bytes and only read less bytes than the requested length if the end of the stream has been reached.

      Parameters:
        `input` - stream to read from
        `b` - buffer to fill
        `offset` - offset into the buffer to start filling at
        `len` - of bytes to read
      Returns:
        the number of bytes actually read
      Throws:
        `IOException` - if an I/O error has occurred

    - #### toByteArray

          public static byte[] toByteArray(InputStream input)
                                    throws IOException

      Gets the contents of an `InputStream` as a `byte[]`.

      This method buffers the input internally, so there is no need to use a `BufferedInputStream`.

      Parameters:
        `input` - the `InputStream` to read from
      Returns:
        the requested byte array
      Throws:
        `NullPointerException` - if the input is null
        `IOException` - if an I/O error occurs
      Since:
        1.5

    - #### closeQuietly

          public static void closeQuietly(Closeable c)

      Closes the given Closeable and swallows any IOException that may occur.
      Parameters:
        `c` - Closeable to close, can be null
      Since:
        1.7

Copyright © 2014 The Apache Software Foundation. All rights reserved.