Class StreamHelper


  • public class StreamHelper
    extends Object

    This class provides primitives for piping streams and readers/writers content.

    Author:
    Fugerit
    • Method Detail

      • checkCloseInput

        public static boolean checkCloseInput​(int modeClose)

        Check if the source should be closed.

        Parameters:
        modeClose - the mode for closing source
        Returns:
        true if the source should be closed, false otherwise.
        See Also:
        StreamIO
      • checkCloseOutput

        public static boolean checkCloseOutput​(int modeClose)

        Check if the destination should be closed.

        Parameters:
        modeClose - the mode for closing destination
        Returns:
        true if the destination should be closed, false otherwise.
        See Also:
        StreamIO
      • pipe

        public static long pipe​(InputStream src,
                                OutputStream dst,
                                int bufferSize,
                                int modeClose)
                         throws IOException

        Pipe the content of a java.io.InputStream into a java.io.OutputStream.

        StreamIO provides constants for bufferSize and closeMode.

        Parameters:
        src - the source
        dst - the destination
        bufferSize - buffer size for reading and writing
        modeClose - the mode for closing source and/or destination
        Returns:
        the number of byte read/written
        Throws:
        IOException - in case of troubles during the operation
        See Also:
        StreamIO
      • pipe

        public static long pipe​(Reader src,
                                Writer dst,
                                int bufferSize,
                                int modeClose)
                         throws IOException

        Pipe the content of a java.io.Reader into a java.io.Writer.

        StreamIO provides constants for bufferSize and closeMode.

        Parameters:
        src - the source
        dst - the destination
        bufferSize - buffer size for reading and writing
        modeClose - the mode for closing source and/or destination
        Returns:
        the number of char read/written
        Throws:
        IOException - in case of troubles during the operation
        See Also:
        StreamIO
      • pipe

        public static long pipe​(InputStream src,
                                OutputStream dst)
                         throws IOException

        Pipe the content of a java.io.InputStream into a java.io.OutputStream.

        StreamIO.BUFFERSIZE_DEFAULT is used as bufferSize, both source and destination are closed at the end.

        Parameters:
        src - the source
        dst - the destination
        Returns:
        the number of byte read/written
        Throws:
        IOException - in case of troubles during the operation
        See Also:
        StreamIO
      • pipe

        public static long pipe​(Reader src,
                                Writer dst)
                         throws IOException

        Pipe the content of a java.io.Reader into a java.io.Writer.

        StreamIO.BUFFERSIZE_DEFAULT is used as bufferSize, both source and destination are closed at the end.

        Parameters:
        src - the source
        dst - the destination
        Returns:
        the number of byte read/written
        Throws:
        IOException - in case of troubles during the operation
        See Also:
        StreamIO
      • closeSafe

        public static boolean closeSafe​(OutputStream out)

        Close an OutputStream, flushing it

        Parameters:
        out - the java.io.OutputStream to close
        Returns:
        true if the stream has been closed without exception, false otherwise
      • closeSafe

        public static boolean closeSafe​(OutputStream out,
                                        boolean flush)

        Close an OutputStream, eventually flushing it

        Parameters:
        out - the java.io.OutputStream to close
        flush - true if the stream should be flushed before closing
        Returns:
        true if the stream has been closed without exception, false otherwise
      • closeSafe

        public static boolean closeSafe​(InputStream in)

        Close an InputStream, eventually flushing it

        Parameters:
        in - the java.io.InputStream to close
        Returns:
        true if the stream has been closed without exception, false otherwise
      • closeSafe

        public static boolean closeSafe​(Writer out)

        Close an Writer, flushing it

        Parameters:
        out - the java.io.Writer to close
        Returns:
        true if the writer has been closed without exception, false otherwise
      • closeSafe

        public static boolean closeSafe​(Writer out,
                                        boolean flush)

        Close an Writer, eventually flushing it

        Parameters:
        out - the java.io.Writer to close
        flush - true if the writer should be flushed before closing
        Returns:
        true if the writer has been closed without exception, false otherwise
      • closeSafe

        public static boolean closeSafe​(Reader in)

        Close an Reader, eventually flushing it

        Parameters:
        in - the java.io.Reader to close
        Returns:
        true if the reader has been closed without exception, false otherwise