Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonChunkedFormat" /> class.
        /// </summary>
        /// <param name="stream">The stream to use to output the chunked data.</param>
        /// <param name="accessMode">Stream access mode for the chunk object.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="accessMode"/> parameter is set to read, but the stream cannot be read.
        /// <para>-or-</para>
        /// <para>Thrown when the accessMode parameter is set to write, but the stream cannot be written.</para>
        /// <para>-or-</para>
        /// <para>Thrown if the stream can't perform seek operations.</para>
        /// </exception>
        protected GorgonChunkedFormat(Stream stream, ChunkAccessMode accessMode)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            ChunkAccessMode = accessMode;

            if (!stream.CanSeek)
            {
                throw new ArgumentException(Resources.GOR_STREAM_NOT_SEEKABLE, "stream");
            }

            if (accessMode == ChunkAccessMode.Write)
            {
                if (!stream.CanWrite)
                {
                    throw new ArgumentException(Resources.GOR_STREAM_IS_READONLY, "accessMode");
                }

                Writer = new GorgonBinaryWriter(stream, true);
            }
            else
            {
                if (!stream.CanRead)
                {
                    throw new ArgumentException(Resources.GOR_STREAM_IS_WRITEONLY, "accessMode");
                }

                Reader = new GorgonBinaryReader(stream, true);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonChunkedFormat" /> class.
        /// </summary>
        /// <param name="stream">The stream to use to output the chunked data.</param>
        /// <param name="accessMode">Stream access mode for the chunk object.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="accessMode"/> parameter is set to read, but the stream cannot be read.
        /// <para>-or-</para>
        /// <para>Thrown when the accessMode parameter is set to write, but the stream cannot be written.</para>
        /// <para>-or-</para>
        /// <para>Thrown if the stream can't perform seek operations.</para>
        /// </exception>
        protected GorgonChunkedFormat(Stream stream, ChunkAccessMode accessMode)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            ChunkAccessMode = accessMode;

            if (!stream.CanSeek)
            {
                throw new ArgumentException(Resources.GOR2DIO_ERR_STREAM_UNSEEKABLE, nameof(stream));
            }

            if (accessMode == ChunkAccessMode.Write)
            {
                if (!stream.CanWrite)
                {
                    throw new ArgumentException(Resources.GOR2DIO_ERR_STREAM_IS_READ_ONLY, nameof(accessMode));
                }

                Writer = new GorgonBinaryWriter(stream, true);
            }
            else
            {
                if (!stream.CanRead)
                {
                    throw new ArgumentException(Resources.GOR2DIO_ERR_STREAM_IS_WRITE_ONLY, nameof(accessMode));
                }

                Reader = new GorgonBinaryReader(stream, true);
            }
        }