Class StreamUtils


  • public class StreamUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      StreamUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void closeSilently​(java.io.Closeable stream)
      Closes a stream, without throwing IOException.
      static void copyStream​(java.io.InputStream input, java.io.OutputStream output)
      Copy an input stream's contents into an output stream.
      static java.lang.String readStreamAsString​(java.io.InputStream stream)  
      static java.lang.String readStreamAsString​(java.io.InputStream stream, boolean includeEndOfLines)  
      static java.lang.String readStreamAsString​(java.io.InputStream stream, boolean includeEndOfLines, java.lang.String encoding)  
      static java.lang.String readStreamAsString​(java.io.InputStream stream, java.lang.String encoding)  
      static void waitForSafely​(java.lang.Process p)
      This should be workaround for https://en.wikipedia.org/wiki/Spurious_wakeup which real can happen in case of processes.
      • Methods inherited from class java.lang.Object

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

      • StreamUtils

        public StreamUtils()
    • Method Detail

      • closeSilently

        public static void closeSilently​(java.io.Closeable stream)
        Closes a stream, without throwing IOException. In IOException is properly logged and consumed
        Parameters:
        stream - the stream that will be closed
      • copyStream

        public static void copyStream​(java.io.InputStream input,
                                      java.io.OutputStream output)
                               throws java.io.IOException
        Copy an input stream's contents into an output stream.
        Parameters:
        input - input stream
        output - stream where to copy input
        Throws:
        java.io.IOException - if IO fails
      • readStreamAsString

        public static java.lang.String readStreamAsString​(java.io.InputStream stream)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readStreamAsString

        public static java.lang.String readStreamAsString​(java.io.InputStream stream,
                                                          java.lang.String encoding)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readStreamAsString

        public static java.lang.String readStreamAsString​(java.io.InputStream stream,
                                                          boolean includeEndOfLines)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readStreamAsString

        public static java.lang.String readStreamAsString​(java.io.InputStream stream,
                                                          boolean includeEndOfLines,
                                                          java.lang.String encoding)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • waitForSafely

        public static void waitForSafely​(java.lang.Process p)
        This should be workaround for https://en.wikipedia.org/wiki/Spurious_wakeup which real can happen in case of processes. See http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2015-June/032350.html thread
        Parameters:
        p - process to be waited for