InvalidDestinationBufferIndex() static private method

static private InvalidDestinationBufferIndex ( int maxLen, int dstOffset, string parameterName ) : ArgumentOutOfRangeException
maxLen int
dstOffset int
parameterName string
return System.ArgumentOutOfRangeException
Example #1
0
        public override long GetBytes(int i, long dataIndex, byte[] buffer, int bufferIndex, int length)
        {
            int maxLen = 0;

            byte[] sourceArray = (byte[])this._values[i];
            maxLen = sourceArray.Length;
            if (dataIndex > 0x7fffffffL)
            {
                throw ADP.InvalidSourceBufferIndex(maxLen, dataIndex, "dataIndex");
            }
            int sourceIndex = (int)dataIndex;

            if (buffer != null)
            {
                try
                {
                    if (sourceIndex < maxLen)
                    {
                        if ((sourceIndex + length) > maxLen)
                        {
                            maxLen -= sourceIndex;
                        }
                        else
                        {
                            maxLen = length;
                        }
                    }
                    Array.Copy(sourceArray, sourceIndex, buffer, bufferIndex, maxLen);
                }
                catch (Exception exception)
                {
                    if (ADP.IsCatchableExceptionType(exception))
                    {
                        maxLen = sourceArray.Length;
                        if (length < 0)
                        {
                            throw ADP.InvalidDataLength((long)length);
                        }
                        if ((bufferIndex < 0) || (bufferIndex >= buffer.Length))
                        {
                            throw ADP.InvalidDestinationBufferIndex(length, bufferIndex, "bufferIndex");
                        }
                        if ((dataIndex < 0L) || (dataIndex >= maxLen))
                        {
                            throw ADP.InvalidSourceBufferIndex(length, dataIndex, "dataIndex");
                        }
                        if ((maxLen + bufferIndex) > buffer.Length)
                        {
                            throw ADP.InvalidBufferSizeOrIndex(maxLen, bufferIndex);
                        }
                    }
                    throw;
                }
            }
            return((long)maxLen);
        }
Example #2
0
        public override long GetChars(int i, long dataIndex, char[]?buffer, int bufferIndex, int length)
        {
            // if the object doesn't contain a char[] then the user will get an exception
            string s = (string)_values[i];

            char[] data = s.ToCharArray();

            int cchars = data.Length;

            // since arrays can't handle 64 bit values and this interface doesn't
            // allow chunked access to data, a dataIndex outside the rang of Int32
            // is invalid
            if (dataIndex > int.MaxValue)
            {
                throw ADP.InvalidSourceBufferIndex(cchars, dataIndex, nameof(dataIndex));
            }

            int ndataIndex = (int)dataIndex;


            // if no buffer is passed in, return the number of characters we have
            if (null == buffer)
            {
                return(cchars);
            }

            try
            {
                if (ndataIndex < cchars)
                {
                    // help the user out in the case where there's less data than requested
                    if ((ndataIndex + length) > cchars)
                    {
                        cchars -= ndataIndex;
                    }
                    else
                    {
                        cchars = length;
                    }
                }

                Array.Copy(data, ndataIndex, buffer, bufferIndex, cchars);
            }
            catch (Exception e) when(ADP.IsCatchableExceptionType(e))
            {
                cchars = data.Length;

                if (length < 0)
                {
                    throw ADP.InvalidDataLength(length);
                }

                // if bad buffer index, throw
                if (bufferIndex < 0 || bufferIndex >= buffer.Length)
                {
                    throw ADP.InvalidDestinationBufferIndex(buffer.Length, bufferIndex, nameof(bufferIndex));
                }

                // if bad data index, throw
                if (ndataIndex < 0 || ndataIndex >= cchars)
                {
                    throw ADP.InvalidSourceBufferIndex(cchars, dataIndex, nameof(dataIndex));
                }

                // if there is not enough room in the buffer for data
                if (cchars + bufferIndex > buffer.Length)
                {
                    throw ADP.InvalidBufferSizeOrIndex(cchars, bufferIndex);
                }
            }

            return(cchars);
        }
Example #3
0
        public override long GetBytes(int i, long dataIndex, byte[]?buffer, int bufferIndex, int length)
        {
            int cbytes;
            int ndataIndex;

            byte[] data = (byte[])_values[i];

            cbytes = data.Length;

            // since arrays can't handle 64 bit values and this interface doesn't
            // allow chunked access to data, a dataIndex outside the rang of Int32
            // is invalid
            if (dataIndex > int.MaxValue)
            {
                throw ADP.InvalidSourceBufferIndex(cbytes, dataIndex, nameof(dataIndex));
            }

            ndataIndex = (int)dataIndex;

            // if no buffer is passed in, return the number of characters we have
            if (null == buffer)
            {
                return(cbytes);
            }

            try
            {
                if (ndataIndex < cbytes)
                {
                    // help the user out in the case where there's less data than requested
                    if ((ndataIndex + length) > cbytes)
                    {
                        cbytes -= ndataIndex;
                    }
                    else
                    {
                        cbytes = length;
                    }
                }

                // until arrays are 64 bit, we have to do these casts
                Array.Copy(data, ndataIndex, buffer, bufferIndex, cbytes);
            }
            catch (Exception e) when(ADP.IsCatchableExceptionType(e))
            {
                cbytes = data.Length;

                if (length < 0)
                {
                    throw ADP.InvalidDataLength(length);
                }

                // if bad buffer index, throw
                if (bufferIndex < 0 || bufferIndex >= buffer.Length)
                {
                    throw ADP.InvalidDestinationBufferIndex(length, bufferIndex, nameof(bufferIndex));
                }

                // if bad data index, throw
                if (dataIndex < 0 || dataIndex >= cbytes)
                {
                    throw ADP.InvalidSourceBufferIndex(length, dataIndex, nameof(dataIndex));
                }

                // if there is not enough room in the buffer for data
                if (cbytes + bufferIndex > buffer.Length)
                {
                    throw ADP.InvalidBufferSizeOrIndex(cbytes, bufferIndex);
                }
            }

            return(cbytes);
        }