示例#1
0
        /// <summary>
        /// Reads a null-terminated UTF-8 string from the stream.
        /// </summary>
        /// <param name="endOffset">The offset that marks the end of the null-terminator search area.</param>
        /// <returns>The string.</returns>
        /// <exception cref="EndOfStreamException">The end of the stream has been reached.</exception>
        /// <exception cref="IOException">The string is longer than <see cref="int.MaxValue"/>.</exception>
        /// <exception cref="ObjectDisposedException">The object has been disposed.</exception>
        public AvifContainer.BoxString ReadBoxString(long endOffset)
        {
            if (endOffset < 0)
            {
                ExceptionUtil.ThrowArgumentOutOfRangeException(nameof(endOffset));
            }

            VerifyNotDisposed();

            AvifContainer.BoxString result;

            int length = GetStringLength(endOffset, out bool hasNullTerminator);

            if (length == 0)
            {
                result = AvifContainer.BoxString.Empty;
            }
            else
            {
                EnsureBuffer(length);

                result = System.Text.Encoding.UTF8.GetString(this.buffer, this.readOffset, length);

                this.readOffset += length;
            }

            if (hasNullTerminator)
            {
                this.Position++; // Skip the null-terminator if one was found at the end of the string.
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Creates the segment.
        /// </summary>
        /// <param name="startOffset">The start offset.</param>
        /// <param name="length">The length.</param>
        /// <returns>The created segment.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="startOffset"/> is greater than the <see cref="EndianBinaryReader"/> length.
        /// -or-
        /// <paramref name="startOffset"/> plus <paramref name="length"/> is greater than the <see cref="EndianBinaryReader"/> length.
        /// </exception>
        public EndianBinaryReaderSegment CreateSegment(long startOffset, long length)
        {
            VerifyNotDisposed();

            long streamLength = this.stream.Length;

            if ((ulong)startOffset > (ulong)streamLength)
            {
                ExceptionUtil.ThrowArgumentOutOfRangeException(nameof(startOffset));
            }

            try
            {
                if (checked (startOffset + length) > streamLength)
                {
                    ExceptionUtil.ThrowArgumentOutOfRangeException(nameof(length));
                }
            }
            catch (OverflowException ex)
            {
                throw new ArgumentOutOfRangeException(nameof(length), ex);
            }

            return(new EndianBinaryReaderSegment(this, startOffset, length));
        }
        public void RemoveAt(int index)
        {
            if ((uint)index >= (uint)this.items.Count)
            {
                ExceptionUtil.ThrowArgumentOutOfRangeException(nameof(index));
            }

            this.items[index]?.Dispose();
            this.items.RemoveAt(index);
            this.version++;
        }
        public void Insert(int index, CompressedAV1Image item)
        {
            if ((uint)index > (uint)this.items.Count)
            {
                ExceptionUtil.ThrowArgumentOutOfRangeException(nameof(index));
            }

            VerifyNotDisposed();

            if (index < this.items.Count)
            {
                this.items[index]?.Dispose();
            }
            this.items.Insert(index, item);
            this.version++;
        }