Package 

Class IOUtils


  • 
    public final class IOUtils
    
                        

    Utility functions

    • Method Summary

      Modifier and Type Method 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.Uses a default buffer size of 8024 bytes.
      static long copy(InputStream input, OutputStream output, int buffersize) Copies the content of a InputStream into an OutputStream
      static long copyRange(InputStream input, long len, OutputStream output) Copies part of the content of a InputStream into an OutputStream.Uses a default buffer size of 8024 bytes.
      static long copyRange(InputStream input, long len, OutputStream output, int buffersize) Copies part of the content of a InputStream into an OutputStream
      static int readFully(InputStream input, Array<byte> array) Reads as much from input as possible to fill the given array.
      static int readFully(InputStream input, Array<byte> array, int offset, int len) Reads as much from input as possible to fill the given arraywith the given amount of bytes.
      static void readFully(ReadableByteChannel channel, ByteBuffer byteBuffer) Reads {@code b.remaining()} bytes from the given channelstarting at the current channel's position.
      static Array<byte> readRange(InputStream input, int len) Gets part of the contents of an {@code InputStream} as a {@code byte[]}.
      static Array<byte> readRange(ReadableByteChannel input, int len) Gets part of the contents of an {@code ReadableByteChannel} as a {@code byte[]}.
      static long skip(InputStream input, long numToSkip) Skips the given number of bytes by repeatedly invoking skip onthe given input stream if necessary.
      static Array<byte> toByteArray(InputStream input) Gets the contents of an {@code InputStream} as a {@code byte[]}.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • closeQuietly

         static void closeQuietly(Closeable c)

        Closes the given Closeable and swallows any IOException that may occur.

        Parameters:
        c - Closeable to close, can be null
      • copy

         static long copy(InputStream input, OutputStream output)

        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, may be null to simulate output to dev/null on Linux and NUL on Windows
      • copy

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

        Copies the content of a InputStream into an OutputStream

        Parameters:
        input - the InputStream to copy
        output - the target, may be null to simulate output to dev/null on Linux and NUL on Windows
        buffersize - the buffer size to use, must be bigger than 0
      • copyRange

         static long copyRange(InputStream input, long len, OutputStream output)

        Copies part of the content of a InputStream into an OutputStream.Uses a default buffer size of 8024 bytes.

        Parameters:
        input - the InputStream to copy
        len - maximum amount of bytes to copy
        output - the target Stream
      • copyRange

         static long copyRange(InputStream input, long len, OutputStream output, int buffersize)

        Copies part of the content of a InputStream into an OutputStream

        Parameters:
        input - the InputStream to copy
        len - maximum amount of bytes to copy
        output - the target, may be null to simulate output to dev/null on Linux and NUL on Windows
        buffersize - the buffer size to use, must be bigger than 0
      • readFully

         static int readFully(InputStream input, Array<byte> array)

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

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

        Parameters:
        input - stream to read from
        array - buffer to fill
      • readFully

         static int readFully(InputStream input, Array<byte> array, int offset, int len)

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

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

        Parameters:
        input - stream to read from
        array - buffer to fill
        offset - offset into the buffer to start filling at
        len - of bytes to read
      • readFully

         static void readFully(ReadableByteChannel channel, ByteBuffer byteBuffer)

        Reads {@code b.remaining()} bytes from the given channelstarting at the current channel's position.

        This method reads repeatedly from the channel until therequested number of bytes are read. This method blocks untilthe requested number of bytes are read, the end of the channelis detected, or an exception is thrown.

        Parameters:
        channel - the channel to read from
        byteBuffer - the buffer into which the data is read.
      • readRange

         static Array<byte> readRange(InputStream input, int len)

        Gets part of the contents of an {@code InputStream} as a {@code byte[]}.

        Parameters:
        input - the {@code InputStream} to read from
        len - maximum amount of bytes to copy
      • readRange

         static Array<byte> readRange(ReadableByteChannel input, int len)

        Gets part of the contents of an {@code ReadableByteChannel} as a {@code byte[]}.

        Parameters:
        input - the {@code ReadableByteChannel} to read from
        len - maximum amount of bytes to copy
      • skip

         static long skip(InputStream input, long numToSkip)

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

        In a case where the stream's skip() method returns 0 beforethe requested number of bytes has been skip this implementationwill fall back to using the read() method.

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

        Parameters:
        input - stream to skip bytes in
        numToSkip - the number of bytes to skip
      • toByteArray

         static Array<byte> toByteArray(InputStream input)

        Gets the contents of an {@code InputStream} as a {@code byte[]}.

        This method buffers the input internally, so there is no need to use a {@code BufferedInputStream}.

        Parameters:
        input - the {@code InputStream} to read from