Class StreamUtils


  • public class StreamUtils
    extends java.lang.Object
    This class supports Helpers on streams.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long closeSilently​(java.io.InputStream inputStream)
      Close silently the InputStream, first consuming any bytes available, ignoring IOException or null object.
      static void closeSilently​(java.nio.channels.Channel channel)  
      static void consumeAnyEntityAndClose​(javax.ws.rs.core.Response response)
      This method consume everything (in particular InpuStream) and close the response.
      static boolean contentEquals​(java.io.InputStream is1, java.io.InputStream is2)  
      static long copy​(java.io.InputStream inputStream, java.io.OutputStream outputStream)
      Copy InputStream to OutputStream efficiently

      InputStream will be closed, but not the OutputStream in order to be compatible with StreamingOutput
      static java.io.InputStream getRemainingReadOnCloseInputStream​(java.io.InputStream inputStream)
      Build an InputStream over the source one that will consume any left data when closing it.
      static java.io.InputStream toInputStream​(java.lang.String source)  
      static java.lang.String toString​(java.io.InputStream inputStream)  
      • Methods inherited from class java.lang.Object

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

      • copy

        public static final long copy​(java.io.InputStream inputStream,
                                      java.io.OutputStream outputStream)
                               throws java.io.IOException
        Copy InputStream to OutputStream efficiently

        InputStream will be closed, but not the OutputStream in order to be compatible with StreamingOutput
        Parameters:
        inputStream -
        outputStream -
        Returns:
        the copied length
        Throws:
        java.io.IOException
      • closeSilently

        public static final long closeSilently​(java.io.InputStream inputStream)
        Close silently the InputStream, first consuming any bytes available, ignoring IOException or null object.
        Parameters:
        inputStream -
        Returns:
        the length in bytes that were read before closing
      • getRemainingReadOnCloseInputStream

        public static final java.io.InputStream getRemainingReadOnCloseInputStream​(java.io.InputStream inputStream)
        Build an InputStream over the source one that will consume any left data when closing it.
        Parameters:
        inputStream -
        Returns:
        the new InputStream to use
      • toString

        public static final java.lang.String toString​(java.io.InputStream inputStream)
                                               throws java.io.IOException
        Parameters:
        inputStream -
        Returns:
        the corresponding String from InputStream
        Throws:
        java.io.IOException
      • toInputStream

        public static java.io.InputStream toInputStream​(java.lang.String source)
        Parameters:
        source -
        Returns:
        the corresponding InputStream
      • contentEquals

        public static boolean contentEquals​(java.io.InputStream is1,
                                            java.io.InputStream is2)
        Parameters:
        is1 -
        is2 -
        Returns:
        True if equals
      • consumeAnyEntityAndClose

        public static void consumeAnyEntityAndClose​(javax.ws.rs.core.Response response)
        This method consume everything (in particular InpuStream) and close the response.
        Parameters:
        response -
      • closeSilently

        public static void closeSilently​(java.nio.channels.Channel channel)