code: private byte[] createBytes(InputStream stream, long length) 
          throws SQLException {
  
          ByteArrayOutputStream buff = null;
  
          try {
              buff = new ByteArrayOutputStream();
  
              if (length > 0) IOUtils.copyLarge(stream, buff, 0, length);
              else IOUtils.copy(stream, buff);
  
              return buff.toByteArray();
          } catch (IOException e) {
              throw new SQLException("Fails to create BLOB", e);
          } finally {
              IOUtils.closeQuietly(buff);
          } // end of finally
      }
docs: Creates bytes array from input stream.
  
  @param stream Input stream
  @param length