Class StreamUtils


  • @ParametersAreNonnullByDefault
    public final class StreamUtils
    extends java.lang.Object
    Utilities for stream data manipulations.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean compareStreams​(java.io.InputStream stream, java.io.InputStream compStream)
      Compares two streams for matching data.
      static void copyFixedSizeInputStreamToOutputStream​(java.io.InputStream source, java.io.OutputStream target, long size)
      Copies data of given size from input stream to output stream using 1k buffer with size limitation.
      static void copyInputStreamToOutputStream​(java.io.InputStream source, java.io.OutputStream target)
      Copies all data from input stream to output stream using 1k buffer.
      static void copyInputStreamToOutputStream​(java.io.InputStream source, java.io.OutputStream target, long size)
      Copies all data from input stream to output stream using 1k buffer with size limitation.
      static void copyInputStreamToTwoOutputStreams​(java.io.InputStream source, java.io.OutputStream target, java.io.OutputStream secondTarget)
      Copies all data from input stream to two output streams using 1k buffer.
      static void skipInputStreamData​(java.io.InputStream source)
      Skips all remaining data from input stream.
      static void skipInputStreamData​(java.io.InputStream source, long skipBytes)
      Skips given amount of data from input stream.
      • Methods inherited from class java.lang.Object

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

      • copyInputStreamToOutputStream

        public static void copyInputStreamToOutputStream​(java.io.InputStream source,
                                                         java.io.OutputStream target)
                                                  throws java.io.IOException
        Copies all data from input stream to output stream using 1k buffer.
        Parameters:
        source - input stream
        target - output stream
        Throws:
        java.io.IOException - if read or write fails
      • copyInputStreamToOutputStream

        public static void copyInputStreamToOutputStream​(java.io.InputStream source,
                                                         java.io.OutputStream target,
                                                         long size)
                                                  throws java.io.IOException
        Copies all data from input stream to output stream using 1k buffer with size limitation.
        Parameters:
        source - input stream
        target - output stream
        size - data size limitation
        Throws:
        java.io.IOException - if read or write fails
      • copyFixedSizeInputStreamToOutputStream

        public static void copyFixedSizeInputStreamToOutputStream​(java.io.InputStream source,
                                                                  java.io.OutputStream target,
                                                                  long size)
                                                           throws java.io.IOException
        Copies data of given size from input stream to output stream using 1k buffer with size limitation.
        Parameters:
        source - input stream
        target - output stream
        size - data size limitation
        Throws:
        java.io.IOException - if read or write fails
      • skipInputStreamData

        public static void skipInputStreamData​(java.io.InputStream source)
                                        throws java.io.IOException
        Skips all remaining data from input stream.
        Parameters:
        source - input stream
        Throws:
        java.io.IOException - if read fails
      • skipInputStreamData

        public static void skipInputStreamData​(java.io.InputStream source,
                                               long skipBytes)
                                        throws java.io.IOException
        Skips given amount of data from input stream.
        Parameters:
        source - input stream
        skipBytes - number of bytes to skip
        Throws:
        java.io.IOException - if skip fails
      • copyInputStreamToTwoOutputStreams

        public static void copyInputStreamToTwoOutputStreams​(java.io.InputStream source,
                                                             java.io.OutputStream target,
                                                             java.io.OutputStream secondTarget)
                                                      throws java.io.IOException
        Copies all data from input stream to two output streams using 1k buffer.
        Parameters:
        source - input stream
        target - output stream
        secondTarget - second output stream
        Throws:
        java.io.IOException - if read or write fails
      • compareStreams

        public static boolean compareStreams​(java.io.InputStream stream,
                                             java.io.InputStream compStream)
                                      throws java.io.IOException
        Compares two streams for matching data.
        Parameters:
        stream - one stream
        compStream - other stream
        Returns:
        true if both streams have same data and length
        Throws:
        java.io.IOException - if read or write fails