Class Streams

java.lang.Object
org.bouncycastle.util.io.Streams

public final class Streams extends Object
Utility methods to assist with stream processing.
  • Constructor Details

    • Streams

      public Streams()
  • Method Details

    • drain

      public static void drain(InputStream inStr) throws IOException
      Read stream till EOF is encountered.
      Parameters:
      inStr - stream to be emptied.
      Throws:
      IOException - in case of underlying IOException.
    • pipeAll

      public static void pipeAll(InputStream inStr, OutputStream outStr) throws IOException
      Write the full contents of inStr to the destination stream outStr.
      Parameters:
      inStr - source input stream.
      outStr - destination output stream.
      Throws:
      IOException - in case of underlying IOException.
    • pipeAll

      public static void pipeAll(InputStream inStr, OutputStream outStr, int bufferSize) throws IOException
      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.
      Throws:
      IOException - in case of underlying IOException.
    • pipeAllLimited

      public static long pipeAllLimited(InputStream inStr, long limit, OutputStream outStr) throws IOException
      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.
      Throws:
      IOException - in case of underlying IOException, or if limit is reached on inStr still has data in it.
    • readAll

      public static byte[] readAll(InputStream inStr) throws IOException
      Read stream fully, returning contents in a byte array.
      Parameters:
      inStr - stream to be read.
      Returns:
      a byte array representing the contents of inStr.
      Throws:
      IOException - in case of underlying IOException.
    • readAllLimited

      public static byte[] readAllLimited(InputStream inStr, int limit) throws IOException
      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.
      Throws:
      IOException - in case of underlying IOException, or if limit is reached on inStr still has data in it.
    • readFully

      public static int readFully(InputStream inStr, byte[] buf) throws IOException
      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.
      Throws:
      IOException - in case of underlying IOException.
    • readFully

      public static int readFully(InputStream inStr, byte[] buf, int off, int len) throws IOException
      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.
      Throws:
      IOException - in case of underlying IOException.
    • validateBufferArguments

      public static void validateBufferArguments(byte[] buf, int off, int len)
    • writeBufTo

      public static void writeBufTo(ByteArrayOutputStream buf, OutputStream output) throws IOException
      Throws:
      IOException