Class DataSourceUtil


  • public final class DataSourceUtil
    extends Object
    Utility methods for DataSource.
    • Method Detail

      • readToEnd

        public static byte[] readToEnd​(DataSource dataSource)
                                throws IOException
        Reads data from the specified opened DataSource until it ends, and returns a byte array containing the read data.
        Parameters:
        dataSource - The source from which to read.
        Returns:
        The concatenation of all read data.
        Throws:
        IOException - If an error occurs reading from the source.
      • readExactly

        public static byte[] readExactly​(DataSource dataSource,
                                         int length)
                                  throws IOException
        Reads length bytes from the specified opened DataSource, and returns a byte array containing the read data.
        Parameters:
        dataSource - The source from which to read.
        Returns:
        The read data.
        Throws:
        IOException - If an error occurs reading from the source.
        IllegalStateException - If the end of the source was reached before length bytes could be read.