public int fromInputStream(final InputStream in, final int maxSize) throws IOException {
    final byte[] buffer = new byte[maxSize];
    int totalBytesCount = 0;
    int readBytesCount;
    while (totalBytesCount < maxSize) {
      readBytesCount = in.read(buffer, totalBytesCount, buffer.length - totalBytesCount);
      if (readBytesCount == -1) {
        break;
      }
      totalBytesCount += readBytesCount;
    }

    if (totalBytesCount == 0) {
      _source = EMPTY_SOURCE;
      _size = 0;
    } else if (totalBytesCount == maxSize) {
      _source = buffer;
      _size = maxSize;
    } else {
      _source = Arrays.copyOf(buffer, totalBytesCount);
      _size = totalBytesCount;
    }
    return _size;
  }
public int fromInputStream(final InputStream in, final int maxSize) throws IOException {
    final byte[] buffer = new byte[maxSize];
    int totalBytesCount = 0;
    int readBytesCount;
    while (totalBytesCount < maxSize) {
      readBytesCount = in.read(buffer, totalBytesCount, buffer.length - totalBytesCount);
      if (readBytesCount == -1) {
        break;
      }
      totalBytesCount += readBytesCount;
    }

    if (totalBytesCount == 0) {
      _source = EMPTY_SOURCE;
      _size = 0;
    } else if (totalBytesCount == maxSize) {
      _source = buffer;
      _size = maxSize;
    } else {
      _source = Arrays.copyOf(buffer, totalBytesCount);
      _size = totalBytesCount;
    }
    return _size;
  }
public int fromInputStream ( final InputStream in , final int maxSize ) throws IOException { final byte [ ] buffer = new byte [ maxSize ] ; int totalBytesCount = 0 ; int readBytesCount ; while ( totalBytesCount < maxSize ) { readBytesCount = in . read ( buffer , totalBytesCount , buffer . length - totalBytesCount ) ; if ( readBytesCount == - 1 ) { break ; } totalBytesCount += readBytesCount ; } if ( totalBytesCount == 0 ) { _source = EMPTY_SOURCE ; _size = 0 ; } else if ( totalBytesCount == maxSize ) { _source = buffer ; _size = maxSize ; } else { _source = Arrays . copyOf ( buffer , totalBytesCount ) ; _size = totalBytesCount ; } return _size ; }
Reads the input stream in memory specifying the maximum bytes to read. This is more efficient than
{@link #fromInputStream(InputStream)} because allocation is made only once.

@param in
Input Stream, use buffered input stream wrapper to speed up reading
@param maxSize
Maximum size to read
@return Buffer count of bytes that are read from the stream. It's also the internal buffer size in bytes
@throws IOException
if an I/O error occurs.
Reads the input stream in memory specifying the maximum bytes to read . This is more efficient than { @link #fromInputStream ( InputStream ) } because allocation is made only once .