Top Description Fields Constructors Methods
org.bouncycastle.util.io

public final Class Streams

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .InputStream, .OutputStream

Utility methods to assist with stream processing.

Field Summary

Modifier and TypeField and Description
private static int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
drain(InputStream
stream to be emptied.
inStr
)

Read stream till EOF is encountered.

public static void
pipeAll(InputStream
source input stream.
inStr
,
OutputStream
destination output stream.
outStr
)

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

public static void
pipeAll(InputStream
source input stream.
inStr
,
OutputStream
destination output stream.
outStr
,
int
the size of temporary buffer to use.
bufferSize
)

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

public static long
pipeAllLimited(InputStream
source input stream.
inStr
,
long
the maximum number of bytes allowed to be read.
limit
,
OutputStream
destination output stream.
outStr
)

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

public static byte[]

Returns:

a byte array representing the contents of inStr.
readAll
(InputStream
stream to be read.
inStr
)

Read stream fully, returning contents in a byte array.

public static byte[]

Returns:

a byte array representing the contents of inStr.
readAllLimited
(InputStream
stream to be read.
inStr
,
int
maximum number of bytes that can be read.
limit
)

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

public static int

Returns:

the number of bytes read into the buffer.
readFully
(InputStream
the stream to be read.
inStr
,
byte[]
the buffer to be read into.
buf
)

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

public static int

Returns:

the number of bytes read into the buffer.
readFully
(InputStream
the stream to be read.
inStr
,
byte[]
the buffer to be read into.
buf
,
int
offset into buf to start putting bytes into.
off
,
int
the number of bytes to be read.
len
)

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

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

public static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFER_SIZEback to summary
private static int BUFFER_SIZE

Constructor Detail

Streamsback to summary
public Streams()

Method Detail

drainback to summary
public static void drain(InputStream inStr) throws IOException

Read stream till EOF is encountered.

Parameters
inStr:InputStream

stream to be emptied.

Exceptions
IOException:
in case of underlying IOException.
pipeAllback to summary
public static void pipeAll(InputStream inStr, OutputStream outStr) throws IOException

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

Parameters
inStr:InputStream

source input stream.

outStr:OutputStream

destination output stream.

Exceptions
IOException:
in case of underlying IOException.
pipeAllback to summary
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:InputStream

source input stream.

outStr:OutputStream

destination output stream.

bufferSize:int

the size of temporary buffer to use.

Exceptions
IOException:
in case of underlying IOException.
pipeAllLimitedback to summary
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:InputStream

source input stream.

limit:long

the maximum number of bytes allowed to be read.

outStr:OutputStream

destination output stream.

Exceptions
IOException:
in case of underlying IOException, or if limit is reached on inStr still has data in it.
readAllback to summary
public static byte[] readAll(InputStream inStr) throws IOException

Read stream fully, returning contents in a byte array.

Parameters
inStr:InputStream

stream to be read.

Returns:byte[]

a byte array representing the contents of inStr.

Exceptions
IOException:
in case of underlying IOException.
readAllLimitedback to summary
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:InputStream

stream to be read.

limit:int

maximum number of bytes that can be read.

Returns:byte[]

a byte array representing the contents of inStr.

Exceptions
IOException:
in case of underlying IOException, or if limit is reached on inStr still has data in it.
readFullyback to summary
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:InputStream

the stream to be read.

buf:byte[]

the buffer to be read into.

Returns:int

the number of bytes read into the buffer.

Exceptions
IOException:
in case of underlying IOException.
readFullyback to summary
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:InputStream

the stream to be read.

buf:byte[]

the buffer to be read into.

off:int

offset into buf to start putting bytes into.

len:int

the number of bytes to be read.

Returns:int

the number of bytes read into the buffer.

Exceptions
IOException:
in case of underlying IOException.
validateBufferArgumentsback to summary
public static void validateBufferArguments(byte[] buf, int off, int len)
writeBufToback to summary
public static void writeBufTo(ByteArrayOutputStream buf, OutputStream output) throws IOException