Stay organized with collections Save and categorize content based on your preferences.

DataSourceUtil

@UnstableApi
public final class DataSourceUtil


Utility methods for DataSource.

Summary

Public constructors

Public methods

static void

Closes a DataSource, suppressing any IOException that may occur.

static byte[]
readExactly(DataSource dataSource, int length)

Reads length bytes from the specified opened DataSource, and returns a byte array containing the read data.

static byte[]
readToEnd(DataSource dataSource)

Reads data from the specified opened DataSource until it ends, and returns a byte array containing the read data.

Public constructors

DataSourceUtil

public DataSourceUtil()

Public methods

closeQuietly

public static void closeQuietly(@Nullable DataSource dataSource)

Closes a DataSource, suppressing any IOException that may occur.

Parameters
@Nullable DataSource dataSource

The DataSource to close.

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.

Returns
byte[]

The read data.

Throws
java.io.IOException java.io.IOException

If an error occurs reading from the source.

java.lang.IllegalStateException java.lang.IllegalStateException

If the end of the source was reached before length bytes could be read.

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 java.io.IOException

If an error occurs reading from the source.