示例#1
0
 /// <summary>
 /// Frees the <c>BLOB</c> reference that this <c>IBlob</c> object
 /// represents, releasing any resources that this object holds to
 /// maintain the reference.
 /// </summary>
 /// <remarks>
 /// An <c>IBlob</c> object is invalid while in the freed state; any
 /// attempt to invoke a method other than <c>Free</c>,
 /// <c>Wrap(object)</c> or <c>Unwrap()</c> while in this state results
 /// in raising an exception. While in a freed state, subsequent calls to
 /// <c>Free()</c> are simply be ignored. After calling <c>Free()</c>,
 /// it may be possible to subsequently transition out of the
 /// freed state by calling <c>Wrap(Object)</c>.
 /// </remarks>
 void IBlob.Free()
 {
     lock (this)
     {
         m_blob = null;
     }
 }
示例#2
0
        public JdbcBlob(java.sql.Blob blob)
        {
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            m_blob = blob;
        }
示例#3
0
        /// <summary>
        /// Initializes this object with up to <c>length</c> octets obtained
        /// from the given <c>stream</c>.
        /// </summary>
        /// <param name="stream">
        /// The <c>System.IO.Stream</c> from which to obtain octets.
        /// </param>
        /// <param name="length">
        /// The maximum number of octets to obtain from the <c>stream</c>.
        /// </param>
        internal void Initialize(Stream stream, int length)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(
                          "stream");
            }
            else if (length < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "length",
                          "value: " + length);
            }

            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    int       bytesRead  = 0;
                    const int bufferSize = 1024;
                    byte[]    buffer     = new byte[bufferSize];

                    while (bytesRead < length)
                    {
                        int count = stream.Read(
                            buffer,
                            0,
                            Math.Min(bufferSize, length - bytesRead));

                        if (count == 0)
                        {
                            break;
                        }

                        ms.Write(buffer, 0, count);

                        bytesRead += count;
                    }

                    m_blob = new org.hsqldb.jdbc.jdbcBlob(ms.ToArray());
                }
            }
            catch (java.sql.SQLException ex)
            {
                throw new HsqlDataSourceException(ex);
            }
            catch (Exception e)
            {
                throw new HsqlDataSourceException(e.ToString(), e);
            }
        }
示例#4
0
        /// <summary>
        /// Wraps the given object, exposing it as an <c>IBlob</c>
        /// through this object.
        /// </summary>
        /// <param name="obj">The object to wrap.</param>
        /// <exception cref="ArgumentException">
        /// When <c>obj</c> is not a <c>java.sql.Blob</c>,
        /// <c>byte[]</c> or <see cref="Stream"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// When <c>obj</c> is <c>null</c>.
        /// </exception>
        /// <exception cref="HsqlDataSourceException">
        /// When this <c>IBlob</c> is not in the freed state.
        /// </exception>
        void IBlob.Wrap(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            else if (obj is java.sql.Blob)
            {
                lock (this)
                {
                    CheckNotFree();

                    m_blob = (java.sql.Blob)obj;
                }
            }
            else if (obj is byte[])
            {
                lock (this)
                {
                    CheckNotFree();

                    try
                    {
                        m_blob = new org.hsqldb.jdbc.jdbcBlob((byte[])obj);
                    }
                    catch (java.sql.SQLException se)
                    {
                        throw new HsqlDataSourceException(se);
                    }
                    catch (java.lang.Exception e)
                    {
                        throw new HsqlDataSourceException(e.toString(), e);
                    }
                }
            }
            else if (obj is Stream)
            {
                lock (this)
                {
                    CheckNotFree();

                    Initialize((Stream)obj, int.MaxValue);
                }
            }
            else
            {
                string message = "typeof(" + obj.GetType() + ")";
                throw new ArgumentException(message, "obj");
            }
        }
示例#5
0
        /// <summary>
        /// Constructs a new <c>JdbcBlob</c> instance that wraps an internally
        /// constructed <c>java.sql.Blob</c> object that, in turn, represents
        /// the given <c>data</c>.
        /// </summary>
        /// <remarks>
        /// Implementation Note: in the interest of efficiency, the specified
        /// <c>data</c> is not currently cloned to ensure isolation; special
        /// care should be taken to avoid modifying the <c>data</c> externally
        /// after being used to construct this object.
        /// </remarks>
        /// <param name="data">
        /// A byte array representing the <c>BLOB</c> data.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the given <c>data</c> is a <c>null</c> reference.
        /// </exception>
        /// <exception cref="HsqlDataSourceException">
        /// If internal construction of the wrapped <c>java.sql.Blob</c>
        /// instance fails for any reason.
        /// </exception>
        public JdbcBlob(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            try
            {
                m_blob = new org.hsqldb.jdbc.jdbcBlob(data);
            }
            catch (java.sql.SQLException ex)
            {
                throw new HsqlDataSourceException(ex);
            }
            catch (Exception e)
            {
                throw new HsqlDataSourceException(e.Message, e);
            }
        }
示例#6
0
        /// <summary>
        /// Retrieves the octet position in the <c>BLOB</c> value designated
        /// by this <c>IBlob</c> object at which <c>pattern</c> begins. The
        /// search begins at position <c>start</c>.
        /// </summary>
        /// <param name="pattern">
        /// The <c>IBlob</c> object designating the <c>BLOB</c> value for
        /// which to search.
        /// </param>
        /// <param name="start">
        /// The position in the <c>BLOB</c> value at which to begin searching;
        /// the first position is 1.
        /// </param>
        /// <returns>
        /// The position at which the pattern begins, else -1.
        /// </returns>
        /// <exception cref="HsqlDataSourceException">
        /// If there is an error accessing the <c>BLOB</c> value.
        /// </exception>
        long IBlob.Position(IBlob pattern, long start)
        {
            lock (this)
            {
                CheckFree();

                try
                {
                    java.sql.Blob wrapped = pattern.UnWrap() as java.sql.Blob;

                    if (wrapped == null)
                    {
                        long length = pattern.Length;

                        if (length > int.MaxValue)
                        {
                            throw new ArgumentException(
                                      "Maximum input length exceeded: " + length,
                                      "pattern");
                        }

                        byte[] bytes = pattern.GetBytes(0, (int)length);

                        return(((IBlob)this).Position(bytes, start));
                    }
                    else
                    {
                        return(m_blob.position(wrapped, start));
                    }
                }
                catch (java.sql.SQLException se)
                {
                    throw new HsqlDataSourceException(se);
                }
                catch (java.lang.Exception e)
                {
                    throw new HsqlDataSourceException(e.toString(), e);
                }
            }
        }
        public JdbcBlob(java.sql.Blob blob)
        {
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            m_blob = blob;
        }
        /// <summary>
        /// Initializes this object with up to <c>length</c> octets obtained
        /// from the given <c>stream</c>.
        /// </summary>
        /// <param name="stream">
        /// The <c>System.IO.Stream</c> from which to obtain octets.
        /// </param>
        /// <param name="length">
        /// The maximum number of octets to obtain from the <c>stream</c>.
        /// </param>
        internal void Initialize(Stream stream, int length)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(
                    "stream");
            }
            else if (length < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "length",
                    "value: " + length);
            }

            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    int bytesRead = 0;
                    const int bufferSize = 1024;
                    byte[] buffer = new byte[bufferSize];

                    while (bytesRead < length)
                    {
                        int count = stream.Read(
                            buffer,
                            0,
                            Math.Min(bufferSize, length - bytesRead));

                        if (count == 0)
                        {
                            break;
                        }

                        ms.Write(buffer, 0, count);

                        bytesRead += count;
                    }

                    m_blob = new org.hsqldb.jdbc.jdbcBlob(ms.ToArray());
                }
            }
            catch (java.sql.SQLException ex)
            {
                throw new HsqlDataSourceException(ex);
            }
            catch (Exception e)
            {
                throw new HsqlDataSourceException(e.ToString(), e);
            }
        }
        /// <summary>
        /// Wraps the given object, exposing it as an <c>IBlob</c>
        /// through this object.
        /// </summary>
        /// <param name="obj">The object to wrap.</param>
        /// <exception cref="ArgumentException">
        /// When <c>obj</c> is not a <c>java.sql.Blob</c>,
        /// <c>byte[]</c> or <see cref="Stream"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// When <c>obj</c> is <c>null</c>.
        /// </exception>
        /// <exception cref="HsqlDataSourceException">
        /// When this <c>IBlob</c> is not in the freed state.
        /// </exception>
        void IBlob.Wrap(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            else if (obj is java.sql.Blob)
            {
                lock (this)
                {
                    CheckNotFree();

                    m_blob = (java.sql.Blob)obj;
                }
            }
            else if (obj is byte[])
            {
                lock (this)
                {
                    CheckNotFree();

                    try
                    {
                        m_blob = new org.hsqldb.jdbc.jdbcBlob((byte[])obj);
                    }
                    catch (java.sql.SQLException se)
                    {
                        throw new HsqlDataSourceException(se);
                    }
                    catch (java.lang.Exception e)
                    {
                        throw new HsqlDataSourceException(e.toString(), e);
                    }
                }
            }
            else if (obj is Stream)
            {
                lock (this)
                {
                    CheckNotFree();

                    Initialize((Stream)obj, int.MaxValue);
                }
            }
            else
            {
                string message = "typeof(" + obj.GetType() + ")";
                throw new ArgumentException(message, "obj");
            }
        }
示例#10
0
 /// <summary>
 /// Frees the <c>BLOB</c> reference that this <c>IBlob</c> object
 /// represents, releasing any resources that this object holds to
 /// maintain the reference.
 /// </summary>
 /// <remarks>
 /// An <c>IBlob</c> object is invalid while in the freed state; any
 /// attempt to invoke a method other than <c>Free</c>,
 /// <c>Wrap(object)</c> or <c>Unwrap()</c> while in this state results
 /// in raising an exception. While in a freed state, subsequent calls to
 /// <c>Free()</c> are simply be ignored. After calling <c>Free()</c>,
 /// it may be possible to subsequently transition out of the
 /// freed state by calling <c>Wrap(Object)</c>.
 /// </remarks>
 void IBlob.Free()
 {
     lock (this)
     {
         m_blob = null;
     }
 }
示例#11
0
        /// <summary>
        /// Constructs a new <c>JdbcBlob</c> instance that wraps an internally
        /// constructed <c>java.sql.Blob</c> object that, in turn, represents
        /// the given <c>data</c>.
        /// </summary>
        /// <remarks>
        /// Implementation Note: in the interest of efficiency, the specified
        /// <c>data</c> is not currently cloned to ensure isolation; special
        /// care should be taken to avoid modifying the <c>data</c> externally
        /// after being used to construct this object.
        /// </remarks>
        /// <param name="data">
        /// A byte array representing the <c>BLOB</c> data.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the given <c>data</c> is a <c>null</c> reference.
        /// </exception>
        /// <exception cref="HsqlDataSourceException">
        /// If internal construction of the wrapped <c>java.sql.Blob</c>
        /// instance fails for any reason.
        /// </exception>
        public JdbcBlob(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            try
            {
                m_blob = new org.hsqldb.jdbc.jdbcBlob(data);
            }
            catch (java.sql.SQLException ex)
            {
                throw new HsqlDataSourceException(ex);
            }
            catch (Exception e)
            {
                throw new HsqlDataSourceException(e.Message, e);
            }
        }
示例#12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public ValueBlob(java.sql.Blob val) throws java.sql.SQLException
        public ValueBlob(java.sql.Blob val)
        {
            blob = new Blob(val);
        }