当前位置: 首页>>代码示例>>C#>>正文


C# StreamMode类代码示例

本文整理汇总了C#中StreamMode的典型用法代码示例。如果您正苦于以下问题:C# StreamMode类的具体用法?C# StreamMode怎么用?C# StreamMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StreamMode类属于命名空间,在下文中一共展示了StreamMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Request

        /// <summary>
        ///     This method is called when stream is requested, if you return a stream
        ///     it will return it to the user else it will keep trying all the other StreamFactorys
        ///     until one does return a stream.
        /// </summary>
        /// <param name="path">Path of file or object to create stream to.</param>
        /// <param name="mode">Determines how to open or create stream.</param>
        /// <returns>A Stream instance or NULL if this factory can't open the given stream.</returns>
        protected override Stream Request(object path, StreamMode mode)
        {
            // if (File.Exists(path.ToString()) == false && moede != StreamMode.Open) return null;
            try
            {
                switch (mode)
                {
                    case StreamMode.Append:
                        if (Directory.Exists(Path.GetDirectoryName(path.ToString()))) Directory.CreateDirectory(Path.GetDirectoryName(path.ToString()));
                        if (File.Exists(path.ToString()) == false) File.Create(path.ToString()).Close();
                        return new FileStream(path.ToString(), FileMode.Append);

                    case StreamMode.Open:
                        return new FileStream(path.ToString(), FileMode.Open);

                    case StreamMode.Truncate:
                        if (Directory.Exists(Path.GetDirectoryName(path.ToString()))) Directory.CreateDirectory(Path.GetDirectoryName(path.ToString()));
                        if (File.Exists(path.ToString()) == false) File.Create(path.ToString()).Close();
                        return new FileStream(path.ToString(), FileMode.Truncate);

                }
            }
            catch (Exception) {}
            return null;
        }
开发者ID:HampsterEater,项目名称:FusionGameEngine,代码行数:33,代码来源:Default+Factory.cs

示例2: QueueStream

 public QueueStream(Stream stream, StreamMode mode, int bufferSize, BufferManager bufferManager)
 {
     if (mode == StreamMode.Read)
     {
         _stream = new ReadStream(stream, bufferSize, bufferManager);
     }
     else if (mode == StreamMode.Write)
     {
         _stream = new WriteStream(new CacheStream(stream, QueueStream.BlockSize, bufferManager), bufferSize, bufferManager);
     }
 }
开发者ID:networkelements,项目名称:Library,代码行数:11,代码来源:QueueStream.cs

示例3: FlacStream

        public FlacStream(string file, StreamMode mode, StreamAccessMode accessMode)
        {
            FileMode fileMode;
            FileAccess fileAccessMode;

            switch (mode)
            {
                case StreamMode.CreateNew:
                {
                    fileMode = FileMode.Create;
                    break;
                }
                case StreamMode.OpenExisting:
                {
                    fileMode = FileMode.Open;
                    break;
                }
                default:
                {
                    throw new FlacDebugException();
                }
            }

            switch (accessMode)
            {
                case StreamAccessMode.Read:
                case StreamAccessMode.Write:
                case StreamAccessMode.Both:
                {
                    fileAccessMode = (FileAccess)accessMode;
                    break;
                }
                default:
                {
                    throw new FlacDebugException();
                }
            }
            fileStream_ = new FileStream(file, fileMode, fileAccessMode, FileShare.Read);

            if ((accessMode & StreamAccessMode.Read) == StreamAccessMode.Read)
            {
                reader_ = new FlacStreamReader(fileStream_);
            }
            if ((accessMode & StreamAccessMode.Write) == StreamAccessMode.Write)
            {
                writer_ = new FlacStreamWriter(fileStream_);
            }
        }
开发者ID:LastContrarian,项目名称:flacfs,代码行数:48,代码来源:FlacStream.cs

示例4: Request

        /// <summary>
        ///     This method is called when stream is requested, if you return a stream
        ///     it will return it to the user else it will keep trying all the other StreamFactorys
        ///     until one does return a stream.
        /// </summary>
        /// <param name="path">Path of file or object to create stream to.</param>
        /// <param name="mode">Determines how to open or create stream.</param>
        /// <returns>A Stream instance or NULL if this factory can't open the given stream.</returns>
        protected override Stream Request(object path,StreamMode mode)
        {
            if (path.ToString().ToLower().Substring(0, 4) != "[email protected]") return null;

            // Check if we have been handed a capacity as well.
            if (path.ToString().Length > 4)
            {
                string capacityStr = path.ToString().Substring(4, path.ToString().Length - 4);
                int capacity = 0;
                if (int.TryParse(capacityStr, out capacity) == true)
                    return new MemoryStream(capacity);
                else
                    return new MemoryStream();
            }
            else
            {
                return new MemoryStream();
            }
        }
开发者ID:HampsterEater,项目名称:FusionGameEngine,代码行数:27,代码来源:Memory+Factory.cs

示例5: BizTalkMessagePartStream

        /// <summary>
        /// Initializes a new instance of the <see cref="BizTalkMessagePartStream"/> class.
        /// </summary>
        /// <param name="stream">The stream from which to read (or write if in compression mode).</param>
        /// <param name="mode">The compression mode.</param>
        public BizTalkMessagePartStream(Stream stream, StreamMode mode)
        {
            this.innerStream = stream;
            this.streamMode = mode;

            if (mode == StreamMode.Write)
            {
                this.writeStream = new BizTalkBlockStream(this.innerStream);
            }
            else if (mode == StreamMode.Read)
            {
                this.reader = new BizTalkBlockReader(stream);
                this.readBuffer = new MemoryStream();
            }
            else
            {
                throw new ArgumentException("Unknown stream mode specified: " + mode, "mode");
            }
        }
开发者ID:niik,项目名称:DtaSpy,代码行数:24,代码来源:BizTalkMessagePartStream.cs

示例6: lock

        Task<int> IStreamReader.ReadAsync(byte[] buffer, int offset, int length, StreamMode mode)
        {
            Utilities.DebugCheckStreamArguments(buffer, offset, length, mode);

            lock (this)
            {
                int total = 0;

                while (length > 0)
                {
                    while (mBuffer == null)
                    {
                        if (mComplete)
                            return Task.FromResult(total);

                        Monitor.Wait(this);
                    }

                    int copied = Math.Min(length, mLength);
                    System.Diagnostics.Debug.Assert(copied > 0);
                    Buffer.BlockCopy(mBuffer, mOffset, buffer, offset, copied);
                    mOffset += copied;
                    mLength -= copied;
                    offset += copied;
                    length -= copied;
                    total += copied;

                    if (mLength == 0)
                    {
                        mBuffer = null;
                        Monitor.PulseAll(this);
                    }

                    if (mode == StreamMode.Partial)
                        break;
                }

                return Task.FromResult(total);
            }
        }
开发者ID:modulexcite,项目名称:managed-lzma,代码行数:40,代码来源:CopyEncoder.cs

示例7: Write

        public override void Write(System.Byte[] buffer, int offset, int count)
        {
            // workitem 7159
            // calculate the CRC on the unccompressed data  (before writing)
            if (crc != null)
                crc.SlurpBlock(buffer, offset, count);

            if (_streamMode == StreamMode.Undefined)
                _streamMode = StreamMode.Writer;
            else if (_streamMode != StreamMode.Writer)
                throw new ZlibException("Cannot Write after Reading.");

            if (count == 0)
                return;

            // first reference of z property will initialize the private var _z
            z.InputBuffer = buffer;
            _z.NextIn = offset;
            _z.AvailableBytesIn = count;
            bool done = false;
            do
            {
                _z.OutputBuffer = workingBuffer;
                _z.NextOut = 0;
                _z.AvailableBytesOut = _workingBuffer.Length;
                int rc = (_wantCompress)
                    ? _z.Deflate(_flushMode)
                    : _z.Inflate(_flushMode);
                if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
                    throw new ZlibException((_wantCompress ? "de" : "in") + "flating: " + _z.Message);

                //if (_workingBuffer.Length - _z.AvailableBytesOut > 0)
                _stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);

                done = _z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0;

                // If GZIP and de-compress, we're done when 8 bytes remain.
                if (_flavor == ZlibStreamFlavor.GZIP && !_wantCompress)
                    done = (_z.AvailableBytesIn == 8 && _z.AvailableBytesOut != 0);

            }
            while (!done);
        }
开发者ID:Cardanis,项目名称:MonoGame,代码行数:43,代码来源:ZlibStream.cs

示例8: Write

        /// <param name="buffer"></param><param name="offset"></param> <param name="count"></param><exception cref = "ZlibException"></exception><exception cref = "ZlibException"></exception>
        public override void Write(byte[] buffer, int offset, int count)
        {
            // workitem 7159
            // calculate the CRC on the unccompressed data  (before writing)
            if (this.crc != null)
            {
                this.crc.SlurpBlock(buffer, offset, count);
            }

            if (this.Mode == StreamMode.Undefined)
            {
                this.Mode = StreamMode.Writer;
            }
            else if (this.Mode != StreamMode.Writer)
            {
                throw new ZlibException("Cannot Write after Reading.");
            }

            if (count == 0)
            {
                return;
            }

            // first reference of z property will initialize the private var _z
            this.Z.InputBuffer = buffer;
            this.ZlibCodec.NextIn = offset;
            this.ZlibCodec.AvailableBytesIn = count;
            bool done;
            do
            {
                this.ZlibCodec.OutputBuffer = this.WorkingBuffer;
                this.ZlibCodec.NextOut = 0;
                this.ZlibCodec.AvailableBytesOut = this.workBuffer.Length;
                int rc = this.WantCompress ? this.ZlibCodec.Deflate(this.flushMode) : this.ZlibCodec.Inflate();
                if (rc != ZlibConstants.Zok && rc != ZlibConstants.ZStreamEnd)
                {
                    throw new ZlibException((this.WantCompress ? "de" : "in") + "flating: " + this.ZlibCodec.Message);
                }

                // if (_workingBuffer.Length - _z.AvailableBytesOut > 0)
                this.Stream.Write(this.workBuffer, 0, this.workBuffer.Length - this.ZlibCodec.AvailableBytesOut);

                done = this.ZlibCodec.AvailableBytesIn == 0 && this.ZlibCodec.AvailableBytesOut != 0;

                // If GZIP and de-compress, we're done when 8 bytes remain.
                if (this.flavor == ZlibStreamFlavor.Gzip && !this.WantCompress)
                {
                    done = this.ZlibCodec.AvailableBytesIn == 8 && this.ZlibCodec.AvailableBytesOut != 0;
                }
            }
            while (!done);
        }
开发者ID:robertbaker,项目名称:SevenUpdate,代码行数:53,代码来源:ZlibBaseStream.cs

示例9: RealizeFont

 /// <summary>
 /// Makes the specified font and brush to the current graphics objects.
 /// </summary>
 void RealizeFont(Glyphs glyphs)
 {
   if (this.streamMode != StreamMode.Text)
   {
     this.streamMode = StreamMode.Text;
     WriteLiteral("BT\n");
     // Text matrix is empty after BT
     this.graphicsState.realizedTextPosition = new XPoint();
   }
   this.graphicsState.RealizeFont(glyphs);
 }
开发者ID:AnthonyNystrom,项目名称:Pikling,代码行数:14,代码来源:PdfContentWriter.cs

示例10: Realize

    /// <summary>
    /// Makes the specified font and brush to the current graphics objects.
    /// </summary>
    void Realize(XFont font, XBrush brush, int renderMode)
    {
      BeginPage();
      RealizeTransform();

      if (this.streamMode != StreamMode.Text)
      {
        this.streamMode = StreamMode.Text;
        this.content.Append("BT\n");
        // Text matrix is empty after BT
        this.gfxState.realizedTextPosition = new XPoint();
      }
      this.gfxState.RealizeFont(font, brush, renderMode);
    }
开发者ID:zheimer,项目名称:PDFSharp,代码行数:17,代码来源:XGraphicsPdfRenderer.cs

示例11: Write

        public override void Write(System.Byte[] buffer, int offset, int length)
        {
            if (_streamMode == StreamMode.Undefined) _streamMode = StreamMode.Writer;
            if (_streamMode != StreamMode.Writer)
                throw new ZlibException("Cannot Write after Reading.");

            if (length == 0)
                return;

            _z.InputBuffer = buffer;
            _z.NextIn = offset;
            _z.AvailableBytesIn = length;
            do
            {
                _z.OutputBuffer = _workingBuffer;
                _z.NextOut = 0;
                _z.AvailableBytesOut = _workingBuffer.Length;
                int rc = (_wantCompress)
                    ? 1
                    : _z.Inflate(_flushMode);
                if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
                    throw new ZlibException((_wantCompress ? "de" : "in") + "flating: " + _z.Message);
                _stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
            }
            while (_z.AvailableBytesIn > 0 || _z.AvailableBytesOut == 0);
        }
开发者ID:Esri,项目名称:arcgis-toolkit-sl-wpf,代码行数:26,代码来源:ZlibStream.cs

示例12: Read

        public override int Read( byte [] buffer, int offset, int count )
        {
            if ( streamMode == StreamMode.Undefined )
            {
                if ( !this.stream.CanRead ) throw new CompressionProcessException ( "The stream is not readable." );
                streamMode = StreamMode.Reader;
                z.AvailableBytesIn = 0;
            }

            if ( streamMode != StreamMode.Reader )
                throw new CompressionProcessException ( "Cannot Read after Writing." );

            if ( count == 0 ) return 0;
            if ( nomoreinput && _wantCompress ) return 0;
            if ( buffer == null ) throw new ArgumentNullException ( "buffer" );
            if ( count < 0 ) throw new ArgumentOutOfRangeException ( "count" );
            if ( offset < buffer.GetLowerBound ( 0 ) ) throw new ArgumentOutOfRangeException ( "offset" );
            if ( ( offset + count ) > buffer.GetLength ( 0 ) ) throw new ArgumentOutOfRangeException ( "count" );

            int rc = 0;

            _z.OutputBuffer = buffer;
            _z.NextOut = offset;
            _z.AvailableBytesOut = count;

            _z.InputBuffer = workingBuffer;

            do
            {
                if ( ( _z.AvailableBytesIn == 0 ) && ( !nomoreinput ) )
                {
                    _z.NextIn = 0;
                    _z.AvailableBytesIn = stream.Read ( _workingBuffer, 0, _workingBuffer.Length );
                    if ( _z.AvailableBytesIn == 0 )
                        nomoreinput = true;
                }
                rc = ( _wantCompress )
                    ? _z.Deflate ( flushMode )
                    : _z.Inflate ( flushMode );

                if ( nomoreinput && ( rc == ZlibConstants.Z_BUF_ERROR ) )
                    return 0;

                if ( rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END )
                    throw new CompressionProcessException ( String.Format ( "{0}flating:  rc={1}  msg={2}", ( _wantCompress ? "de" : "in" ), rc, _z.Message ) );

                if ( ( nomoreinput || rc == ZlibConstants.Z_STREAM_END ) && ( _z.AvailableBytesOut == count ) )
                    break;
            }
            while ( _z.AvailableBytesOut > 0 && !nomoreinput && rc == ZlibConstants.Z_OK );

            if ( _z.AvailableBytesOut > 0 )
            {
                if ( rc == ZlibConstants.Z_OK && _z.AvailableBytesIn == 0 )
                {

                }

                if ( nomoreinput )
                {
                    if ( _wantCompress )
                    {
                        rc = _z.Deflate ( FlushType.Finish );
                        if ( rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END )
                            throw new CompressionProcessException ( String.Format ( "Deflating:  rc={0}  msg={1}", rc, _z.Message ) );
                    }
                }
            }

            rc = ( count - _z.AvailableBytesOut );

            return rc;
        }
开发者ID:Daramkun,项目名称:ProjectLiqueur,代码行数:73,代码来源:ZlibBaseStream.cs

示例13: WriteAsync

        public Task<int> WriteAsync(byte[] buffer, int offset, int length, StreamMode mode)
        {
            Utilities.CheckStreamArguments(buffer, offset, length, mode);

            int processed = 0;

            while (length > 0)
            {
                Frame frame;
                lock (mSyncObject)
                {
                    System.Diagnostics.Debug.Assert(mRunning);

                    if (mDisposeTask != null)
                        throw new OperationCanceledException();

                    while (mQueue.Count == 0)
                    {
                        Monitor.Wait(mSyncObject);

                        if (mDisposeTask != null)
                            throw new OperationCanceledException();
                    }

                    frame = mQueue.Peek();
                }

                var capacity = frame.mEnding - frame.mOffset;
                var copySize = Math.Min(capacity, length > Int32.MaxValue ? Int32.MaxValue : (int)length);
                Buffer.BlockCopy(buffer, offset, frame.mBuffer, frame.mOffset, copySize);
                frame.mOffset += copySize;
                offset += copySize;
                processed += copySize;
                length -= copySize;

                if (copySize == capacity || frame.mMode == StreamMode.Partial)
                {
                    frame.mCompletion.SetResult(frame.mOffset - frame.mOrigin);

                    lock (mSyncObject)
                    {
                        System.Diagnostics.Debug.Assert(mRunning);
                        var other = mQueue.Dequeue();
                        System.Diagnostics.Debug.Assert(other == frame);
                    }
                }
            }

            return Task.FromResult(processed);
        }
开发者ID:modulexcite,项目名称:managed-lzma,代码行数:50,代码来源:StreamHelper.cs

示例14: ReadAsync

        public Task<int> ReadAsync(byte[] buffer, int offset, int length, StreamMode mode)
        {
            Utilities.CheckStreamArguments(buffer, offset, length, mode);

            var frame = new Frame();
            frame.mBuffer = buffer;
            frame.mOrigin = offset;
            frame.mOffset = offset;
            frame.mEnding = offset + length;
            frame.mMode = mode;

            lock (mSyncObject)
            {
                if (mDisposeTask != null)
                    throw new ObjectDisposedException(null);

                mQueue.Enqueue(frame);
                Monitor.Pulse(mSyncObject);
            }

            return frame.mCompletion.Task;
        }
开发者ID:modulexcite,项目名称:managed-lzma,代码行数:22,代码来源:StreamHelper.cs

示例15: Write

        public override void Write( System.Byte [] buffer, int offset, int count )
        {
            if ( streamMode == StreamMode.Undefined )
                streamMode = StreamMode.Writer;
            else if ( streamMode != StreamMode.Writer )
                throw new CompressionProcessException ( "Cannot Write after Reading." );

            if ( count == 0 )
                return;

            z.InputBuffer = buffer;
            _z.NextIn = offset;
            _z.AvailableBytesIn = count;
            bool done = false;
            do
            {
                _z.OutputBuffer = workingBuffer;
                _z.NextOut = 0;
                _z.AvailableBytesOut = _workingBuffer.Length;
                int rc = ( _wantCompress )
                    ? _z.Deflate ( flushMode )
                    : _z.Inflate ( flushMode );
                if ( rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END )
                    throw new CompressionProcessException ( ( _wantCompress ? "de" : "in" ) + "flating: " + _z.Message );

                stream.Write ( _workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut );

                done = _z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0;
            }
            while ( !done );
        }
开发者ID:Daramkun,项目名称:ProjectLiqueur,代码行数:31,代码来源:ZlibBaseStream.cs


注:本文中的StreamMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。