DataSourceUtil
@UnstableApi
public final class DataSourceUtil
Utility methods for DataSource.
Summary
Public methods |
|
|---|---|
static void |
closeQuietly(@Nullable DataSource dataSource)Closes a |
static byte[] |
readExactly(DataSource dataSource, int length)Reads |
static byte[] |
readToEnd(DataSource dataSource)Reads data from the specified opened |
Public methods
closeQuietly
public static void closeQuietly(@Nullable DataSource dataSource)
Closes a DataSource, suppressing any IOException that may occur.
| Parameters | |
|---|---|
@Nullable DataSource dataSource |
The |
readExactly
public static byte[] readExactly(DataSource dataSource, int length)
Reads length bytes from the specified opened DataSource, and returns a byte array containing the read data.
| Parameters | |
|---|---|
DataSource dataSource |
The source from which to read. |
int length |
The number of bytes to read. |
| Returns | |
|---|---|
byte[] |
The read data. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs reading from the source. |
java.lang.IllegalStateException |
If the end of the source was reached before |
readToEnd
public static byte[] readToEnd(DataSource dataSource)
Reads data from the specified opened DataSource until it ends, and returns a byte array containing the read data.
| Parameters | |
|---|---|
DataSource dataSource |
The source from which to read. |
| Returns | |
|---|---|
byte[] |
The concatenation of all read data. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs reading from the source. |