Class StreamIO


  • public class StreamIO
    extends Object

    StreamIO provides API for managing stream, reader an writer.

    Author:
    fugerit
    • Field Detail

      • MODE_CLOSE_NONE

        public static final int MODE_CLOSE_NONE
        Don't invoke close() method on source and destination at the end of operation.
        See Also:
        Constant Field Values
      • MODE_CLOSE_BOTH

        public static final int MODE_CLOSE_BOTH
        Invoke close() method on both source and destination at the end of operation.
        See Also:
        Constant Field Values
      • MODE_CLOSE_IN_ONLY

        public static final int MODE_CLOSE_IN_ONLY
        Invoke close() method on ource only at the end of operation.
        See Also:
        Constant Field Values
      • MODE_CLOSE_OUT_ONLY

        public static final int MODE_CLOSE_OUT_ONLY
        Invoke close() method on destination only at the end of operation.
        See Also:
        Constant Field Values
      • BUFFERSIZE_LOW

        public static final int BUFFERSIZE_LOW
        Small size buffer.
        See Also:
        Constant Field Values
      • BUFFERSIZE_MEDIUM

        public static final int BUFFERSIZE_MEDIUM
        Medium size buffer.
        See Also:
        Constant Field Values
      • BUFFERSIZE_HIGH

        public static final int BUFFERSIZE_HIGH
        Big size buffer.
        See Also:
        Constant Field Values
      • BUFFERSIZE_NOBUFFER

        public static final int BUFFERSIZE_NOBUFFER
        No buffer at all (size = 1)
        See Also:
        Constant Field Values
    • Method Detail

      • readString

        public static String readString​(InputStream src)
                                 throws IOException

        Read an InputStream as a String.

        Parameters:
        src - the input stream
        Returns:
        the String
        Throws:
        IOException - in case of troubles during the operation
      • readString

        public static String readString​(Reader src)
                                 throws IOException

        Read an Reader as a String.

        Parameters:
        src - the input stream
        Returns:
        the String
        Throws:
        IOException - in case of troubles during the operation
      • readBytes

        public static byte[] readBytes​(InputStream src)
                                throws IOException

        Read an InputStream as a byte array.

        Parameters:
        src - the input stream
        Returns:
        the byte array
        Throws:
        IOException - in case of troubles during the operation
      • pipeChar

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

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

        Parameters:
        src - the source
        dst - the destination
        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
      • pipeCharCloseBoth

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

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

        Parameters:
        src - the source
        dst - the destination
        Returns:
        the number of char read/written
        Throws:
        IOException - in case of troubles during the operation
      • pipeStream

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

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

        Parameters:
        src - the source
        dst - the destination
        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
      • pipeStreamCloseBoth

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

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

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