private static ValueLob createBlob(InputStream in,long length,DataHandler handler){
  try {
    if (handler == null) {
      byte[] data=IOUtils.readBytesAndClose(in,(int)length);
      return createSmallLob(Value.BLOB,data);
    }
    long remaining=Long.MAX_VALUE;
    boolean compress=handler.getLobCompressionAlgorithm(Value.BLOB) != null;
    if (length >= 0 && length < remaining) {
      remaining=length;
    }
    int len=getBufferSize(handler,compress,remaining);
    byte[] buff;
    if (len >= Integer.MAX_VALUE) {
      buff=IOUtils.readBytesAndClose(in,-1);
      len=buff.length;
    }
 else {
      buff=DataUtils.newBytes(len);
      len=IOUtils.readFully(in,buff,len);
    }
    if (len <= handler.getMaxLengthInplaceLob()) {
      byte[] small=DataUtils.newBytes(len);
      System.arraycopy(buff,0,small,0,len);
      return ValueLob.createSmallLob(Value.BLOB,small);
    }
    ValueLob lob=new ValueLob(Value.BLOB,null);
    lob.createFromStream(buff,len,in,remaining,handler);
    return lob;
  }
 catch (  IOException e) {
    throw DbException.convertIOException(e,null);
  }
}

private static ValueLob createBlob ( InputStream in , long length , DataHandler handler ) { try { if ( handler == null ) { byte [ ] data = IOUtils . readBytesAndClose ( in , ( int ) length ) ; return createSmallLob ( Value . BLOB , data ) ; } long remaining = Long . MAX_VALUE ; boolean compress = handler . getLobCompressionAlgorithm ( Value . BLOB ) != null ; if ( length >= 0 && length < remaining ) { remaining = length ; } int len = getBufferSize ( handler , compress , remaining ) ; byte [ ] buff ; if ( len >= Integer . MAX_VALUE ) { buff = IOUtils . readBytesAndClose ( in , - 1 ) ; len = buff . length ; } else { buff = DataUtils . newBytes ( len ) ; len = IOUtils . readFully ( in , buff , len ) ; } if ( len <= handler . getMaxLengthInplaceLob ( ) ) { byte [ ] small = DataUtils . newBytes ( len ) ; System . arraycopy ( buff , 0 , small , 0 , len ) ; return ValueLob . createSmallLob ( Value . BLOB , small ) ; } ValueLob lob = new ValueLob ( Value . BLOB , null ) ; lob . createFromStream ( buff , len , in , remaining , handler ) ; return lob ; } catch ( IOException e ) { throw DbException . convertIOException ( e , null ) ; } }
create a blob value from a stream .
