Class InOuts


  • public class InOuts
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  InOuts.ByteReadConsumer  
    • Constructor Summary

      Constructors 
      Constructor Description
      InOuts()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] bytes​(java.io.InputStream input)
      Reads all bytes from input to a byte array AND will close input at EOF.
      static byte[] bytes​(java.io.InputStream input, boolean close)
      Reads all bytes from input to a byte array AND will optionally close the input at EOF.
      static void close​(java.io.InputStream input)
      Null-safe closing of an inputstream (but will still throw an IOException)
      static void close​(java.io.OutputStream output)
      Null-safe closing of an outputstream (but will still throw an IOException)
      static void closeQuietly​(java.io.InputStream input)
      Null-safe closing of an inputstream AND any exception during the close will be discarded.
      static void closeQuietly​(java.io.OutputStream output)
      Null-safe closing of an ouputstream AND any exception during the close will be discarded.
      static long consume​(java.io.InputStream input, int bufferSize, InOuts.ByteReadConsumer consumer)
      Consumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code.
      static long consume​(java.io.InputStream input, InOuts.ByteReadConsumer consumer)
      Consumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code.
      static long copy​(java.io.InputStream input, java.io.OutputStream output)
      Copies an input stream to an output stream in chunks (the buffer size).
      static long copy​(java.io.InputStream input, java.io.OutputStream output, int bufferSize)
      Copies an input stream to an output stream in chunks (the buffer size).
      static java.lang.String string​(java.io.InputStream input, java.nio.charset.Charset charset)  
      static java.lang.String string​(java.io.InputStream input, java.nio.charset.Charset charset, boolean close)  
      static java.lang.String stringUTF8​(java.io.InputStream input)  
      static java.lang.String stringUTF8​(java.io.InputStream input, boolean close)  
      • Methods inherited from class java.lang.Object

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

      • InOuts

        public InOuts()
    • Method Detail

      • close

        public static void close​(java.io.InputStream input)
                          throws java.io.IOException
        Null-safe closing of an inputstream (but will still throw an IOException)
        Parameters:
        input -
        Throws:
        java.io.IOException
      • close

        public static void close​(java.io.OutputStream output)
                          throws java.io.IOException
        Null-safe closing of an outputstream (but will still throw an IOException)
        Parameters:
        output -
        Throws:
        java.io.IOException
      • closeQuietly

        public static void closeQuietly​(java.io.InputStream input)
        Null-safe closing of an inputstream AND any exception during the close will be discarded.
        Parameters:
        input -
      • closeQuietly

        public static void closeQuietly​(java.io.OutputStream output)
        Null-safe closing of an ouputstream AND any exception during the close will be discarded.
        Parameters:
        output -
      • bytes

        public static byte[] bytes​(java.io.InputStream input)
                            throws java.io.IOException
        Reads all bytes from input to a byte array AND will close input at EOF.
        Parameters:
        input -
        Returns:
        Throws:
        java.io.IOException
      • bytes

        public static byte[] bytes​(java.io.InputStream input,
                                   boolean close)
                            throws java.io.IOException
        Reads all bytes from input to a byte array AND will optionally close the input at EOF.
        Parameters:
        input -
        Returns:
        Throws:
        java.io.IOException
      • string

        public static java.lang.String string​(java.io.InputStream input,
                                              java.nio.charset.Charset charset)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • string

        public static java.lang.String string​(java.io.InputStream input,
                                              java.nio.charset.Charset charset,
                                              boolean close)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • stringUTF8

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

        public static java.lang.String stringUTF8​(java.io.InputStream input,
                                                  boolean close)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • copy

        public static long copy​(java.io.InputStream input,
                                java.io.OutputStream output)
                         throws java.io.IOException
        Copies an input stream to an output stream in chunks (the buffer size). Does NOT close the input or output streams.
        Parameters:
        input -
        output -
        Returns:
        Throws:
        java.io.IOException
      • copy

        public static long copy​(java.io.InputStream input,
                                java.io.OutputStream output,
                                int bufferSize)
                         throws java.io.IOException
        Copies an input stream to an output stream in chunks (the buffer size). Does NOT close the input or output streams.
        Parameters:
        input -
        output -
        bufferSize -
        Returns:
        Throws:
        java.io.IOException
      • consume

        public static long consume​(java.io.InputStream input,
                                   InOuts.ByteReadConsumer consumer)
                            throws java.io.IOException
        Consumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code. Does NOT close the inputstream.
        Parameters:
        input -
        consumer -
        Returns:
        Throws:
        java.io.IOException
      • consume

        public static long consume​(java.io.InputStream input,
                                   int bufferSize,
                                   InOuts.ByteReadConsumer consumer)
                            throws java.io.IOException
        Consumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code. Does NOT close the inputstream.
        Parameters:
        input -
        bufferSize -
        consumer -
        Returns:
        Throws:
        java.io.IOException