net.rim.device.api.io
Class IOUtilities

java.lang.Object
  extended by net.rim.device.api.io.IOUtilities

public class IOUtilities
extends Object

Helper functions for I/O.

Since:
BlackBerry API 4.2.0

Method Summary
static byte[] streamToBytes(InputStream stream)
          Reads all bytes from an InputStream and returns them in a byte array.
static byte[] streamToBytes(InputStream stream, int increment)
          Reads all bytes from an InputStream and returns them in a byte array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Method Detail

streamToBytes

public static byte[] streamToBytes(InputStream stream)
                            throws IOException
Reads all bytes from an InputStream and returns them in a byte array.

This method simply invokes IOUtilities.streamToBytes(InputStream, int) with the given InputStream and increment==1024.

Parameters:
stream - the InputStream whose bytes to read; may be null
Returns:
a newly-created byte array whose length is equal to the number of bytes read from the given InputStream and whose elements are those bytes; returns null if and only if stream==null
Throws:
IOException - if reading from stream throws it
Since:
BlackBerry API 4.2.0

streamToBytes

public static byte[] streamToBytes(InputStream stream,
                                   int increment)
                            throws IOException
Reads all bytes from an InputStream and returns them in a byte array.

This method repeatedly invokes InputStream.read(byte[], int, int) on the given InputStream, reading a chunks of bytes whose size is based on the value provided for increment. Once the end of the stream is reached, a byte array containing the bytes read is returned.

This method uses some VM optimizations to avoid repeatedly creating new arrays and is considered to be very efficient.

Parameters:
stream - the InputStream whose bytes to read; may be null
increment - the suggested number of bytes to read at a time
Returns:
a newly-created byte array whose length is equal to the number of bytes read from the given InputStream and whose elements are those bytes; returns null if and only if stream==null
Throws:
IOException - if reading from stream throws it
IllegalArgumentException - if increment is less than or equal to 0 (zero)
Since:
BlackBerry API 4.2.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal