Class Streams

  • All Implemented Interfaces:

    
    public final class Streams
    
                        

    Utility methods to assist with stream processing.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Streams()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static void drain(InputStream inStr) Read stream till EOF is encountered.
      static Array<byte> readAll(InputStream inStr) Read stream fully, returning contents in a byte array.
      static Array<byte> readAllLimited(InputStream inStr, int limit) Read from inStr up to a maximum number of bytes, throwing an exception if more the maximum amount of requested data is available.
      static int readFully(InputStream inStr, Array<byte> buf) Fully read in buf's length in data, or up to EOF, whichever occurs first,
      static int readFully(InputStream inStr, Array<byte> buf, int off, int len) Fully read in len's bytes of data into buf, or up to EOF, whichever occurs first,
      static void pipeAll(InputStream inStr, OutputStream outStr) Write the full contents of inStr to the destination stream outStr.
      static void pipeAll(InputStream inStr, OutputStream outStr, int bufferSize) Write the full contents of inStr to the destination stream outStr.
      static long pipeAllLimited(InputStream inStr, long limit, OutputStream outStr) Write up to limit bytes of data from inStr to the destination stream outStr.
      static void writeBufTo(ByteArrayOutputStream buf, OutputStream output)
      • Methods inherited from class java.lang.Object

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

      • Streams

        Streams()
    • Method Detail

      • drain

         static void drain(InputStream inStr)

        Read stream till EOF is encountered.

        Parameters:
        inStr - stream to be emptied.
      • readAll

         static Array<byte> readAll(InputStream inStr)

        Read stream fully, returning contents in a byte array.

        Parameters:
        inStr - stream to be read.
        Returns:

        a byte array representing the contents of inStr.

      • readAllLimited

         static Array<byte> readAllLimited(InputStream inStr, int limit)

        Read from inStr up to a maximum number of bytes, throwing an exception if more the maximum amount of requested data is available.

        Parameters:
        inStr - stream to be read.
        limit - maximum number of bytes that can be read.
        Returns:

        a byte array representing the contents of inStr.

      • readFully

         static int readFully(InputStream inStr, Array<byte> buf)

        Fully read in buf's length in data, or up to EOF, whichever occurs first,

        Parameters:
        inStr - the stream to be read.
        buf - the buffer to be read into.
        Returns:

        the number of bytes read into the buffer.

      • readFully

         static int readFully(InputStream inStr, Array<byte> buf, int off, int len)

        Fully read in len's bytes of data into buf, or up to EOF, whichever occurs first,

        Parameters:
        inStr - the stream to be read.
        buf - the buffer to be read into.
        off - offset into buf to start putting bytes into.
        len - the number of bytes to be read.
        Returns:

        the number of bytes read into the buffer.

      • pipeAll

         static void pipeAll(InputStream inStr, OutputStream outStr)

        Write the full contents of inStr to the destination stream outStr.

        Parameters:
        inStr - source input stream.
        outStr - destination output stream.
      • pipeAll

         static void pipeAll(InputStream inStr, OutputStream outStr, int bufferSize)

        Write the full contents of inStr to the destination stream outStr.

        Parameters:
        inStr - source input stream.
        outStr - destination output stream.
        bufferSize - the size of temporary buffer to use.
      • pipeAllLimited

         static long pipeAllLimited(InputStream inStr, long limit, OutputStream outStr)

        Write up to limit bytes of data from inStr to the destination stream outStr.

        Parameters:
        inStr - source input stream.
        limit - the maximum number of bytes allowed to be read.
        outStr - destination output stream.