Overview | Package | Class | Tree | Deprecated | Index | Help
| Bouncy Castle Cryptography Library 1.85
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.bouncycastle.util.io
Class Streams

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

public final class Streams
extends java.lang.Object

Utility methods to assist with stream processing.

Constructor Summary
`Streams()`

Method Summary
`static void` | `drain(java.io.InputStream inStr)` Read stream till EOF is encountered.
`static void` | `pipeAll(java.io.InputStream inStr, java.io.OutputStream outStr)` Write the full contents of inStr to the destination stream outStr.
`static void` | `pipeAll(java.io.InputStream inStr, java.io.OutputStream outStr, int bufferSize)` Write the full contents of inStr to the destination stream outStr.
`static long` | `pipeAllLimited(java.io.InputStream inStr, long limit, java.io.OutputStream outStr)` Write up to limit bytes of data from inStr to the destination stream outStr.
`static byte[]` | `readAll(java.io.InputStream inStr)` Read stream fully, returning contents in a byte array.
`static byte[]` | `readAllLimited(java.io.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(java.io.InputStream inStr, byte[] buf)` Fully read in buf's length in data, or up to EOF, whichever occurs first,
`static int` | `readFully(java.io.InputStream inStr, byte[] buf, int off, int len)` Fully read in len's bytes of data into buf, or up to EOF, whichever occurs first,
`static byte[]` | `readLenBytesFully(java.io.InputStream inStr, int len)` Read exactly bytes from and return them as a newly allocated array.
`static void` | `validateBufferArguments(byte[] buf, int off, int len)`
`static void` | `writeBufTo(java.io.ByteArrayOutputStream buf, java.io.OutputStream output)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Streams

    public Streams()

Method Detail

### drain

    public static void drain(java.io.InputStream inStr)
                      throws java.io.IOException

  Read stream till EOF is encountered.

  Parameters:
    `inStr` - stream to be emptied.
  Throws:
    `java.io.IOException` - in case of underlying IOException.

### pipeAll

    public static void pipeAll(java.io.InputStream inStr,
                               java.io.OutputStream outStr)
                        throws java.io.IOException

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

  Parameters:
    `inStr` - source input stream.
    `outStr` - destination output stream.
  Throws:
    `java.io.IOException` - in case of underlying IOException.

### pipeAll

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

### pipeAllLimited

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

### readAll

    public static byte[] readAll(java.io.InputStream inStr)
                          throws java.io.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:
    `java.io.IOException` - in case of underlying IOException.

### readAllLimited

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

### readFully

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

### readFully

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

### readLenBytesFully

    public static byte[] readLenBytesFully(java.io.InputStream inStr,
                                           int len)
                                    throws java.io.IOException

  Read exactly bytes from and return them as a newly allocated array.

  Unlike followed by `readFully(InputStream, byte[])`, the returned array is grown incrementally as data arrives rather than allocated at the full declared length up front. A caller passing an untrusted (possibly hostile) length therefore cannot drive a large allocation from a short input - the allocation tracks the bytes the stream actually delivers, and a stream that ends before bytes have been read fails with an `EOFException`.

  Parameters:
    `inStr` - the stream to read from.
    `len` - the exact number of bytes to read.
  Returns:
    a containing the bytes read.
  Throws:
    `java.io.EOFException` - if the stream ends before bytes are available.
    `java.io.IOException` - on an underlying read error.
    `java.lang.IllegalArgumentException` - if is negative.

### validateBufferArguments

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

### writeBufTo

    public static void writeBufTo(java.io.ByteArrayOutputStream buf,
                                  java.io.OutputStream output)
                           throws java.io.IOException

  Throws:
    `java.io.IOException`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Bouncy Castle Cryptography Library 1.85
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD