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


C# Stream.ShouldNotBeNull方法代码示例

本文整理汇总了C#中Stream.ShouldNotBeNull方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ShouldNotBeNull方法的具体用法?C# Stream.ShouldNotBeNull怎么用?C# Stream.ShouldNotBeNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


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

示例1: Decompress

        /// <summary>
        /// 지정한 데이터를 압축하여, <paramref name="destinationStream"/> 에 저장합니다.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="destinationStream"></param>
        public virtual void Decompress(byte[] input, Stream destinationStream) {
            input.ShouldNotBeNull("input");
            destinationStream.ShouldNotBeNull("destinationStream");

            var decompressedBytes = Decompress(input);
            destinationStream.Write(decompressedBytes, 0, decompressedBytes.Length);
        }
开发者ID:debop,项目名称:NFramework,代码行数:12,代码来源:CompressAdapter.cs

示例2: HtmlEncode

        /// <summary>
        /// 지정된 스트림을 Html 형식으로 Encoding한다.
        /// </summary>
        /// <param name="stream">스트림</param>
        /// <returns>인코딩된 문자열</returns>
        public static string HtmlEncode(Stream stream) {
            stream.ShouldNotBeNull("stream");

            return HtmlEncode(stream.ToText());

            // return HtmlEncode(StringTool.ToString(stream));
        }
开发者ID:debop,项目名称:NFramework,代码行数:12,代码来源:HtmlTool.cs

示例3: UploadFile

        public static MongoGridFSFileInfo UploadFile(this IMongoRepository repository, string remoteFilename, Stream stream,
                                                     MongoGridFSCreateOptions createOptions) {
            stream.ShouldNotBeNull("stream");
            remoteFilename.ShouldNotBeWhiteSpace("remoteFilename");

            return repository.GridFS.Upload(stream, remoteFilename, createOptions);
        }
开发者ID:debop,项目名称:NFramework,代码行数:7,代码来源:MongoRepository.GridFS.cs

示例4: TransferStream

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="writableTargetStream">실제 Data가 쓰일 대상 Stream</param>
        public TransferStream(Stream writableTargetStream) {
            writableTargetStream.ShouldNotBeNull("writableTargetStream");
            Guard.Assert(writableTargetStream.CanWrite, "Target stream is not writable.");

            _writableTargetStream = writableTargetStream;
            _chunks = new BlockingCollection<byte[]>();

            // _chunks 에 입력이 들어올 때까지 기다렸다가, 대상 Stream에 쓰는 Background 작업을 정의합니다.
            _processingTask =
                Task.Factory.StartNew(() => {
                                          if(IsDebugEnabled)
                                              log.Debug("스트림 정보 복사를 시작합니다...");

                                          foreach(var chunk in _chunks.GetConsumingEnumerable())
                                              _writableTargetStream.Write(chunk, 0, chunk.Length);

                                          if(IsDebugEnabled)
                                              log.Debug("스트림 정보 복사를 완료되었습니다!!!");
                                      });
        }
开发者ID:debop,项目名称:NFramework,代码行数:24,代码来源:TransferStream.cs

示例5: PostStream

        /// <summary>
        /// POST 방식으로 서버에 접속하여 응답 Stream을 반환 받는다.
        /// </summary>
        /// <param name="stream">서버에 전달할 내용</param>
        /// <returns></returns>
        protected virtual Stream PostStream(Stream stream) {
            stream.ShouldNotBeNull("stream");

            if(IsDebugEnabled)
                log.Debug("지정된 스트림을 전송합니다.");

            Request.Credentials = GetCredentials();
            Request.Method = WebRequestMethods.Http.Post;
            Request.ContentType = POST_CONTENT_TYPE;

            if(stream == null) {
                Request.ContentLength = 0;
            }
            if(stream != null) {
                byte[] payload = stream.ToBytes();

                using(var requestStream = Request.GetRequestStream())
                using(var bw = new BinaryWriter(requestStream, XmlTool.XmlEncoding)) {
                    bw.Write(payload);
                }
            }

            return IsAsync
                       ? With.TryFunctionAsync(() => Request.GetResponseStreamAsync().Result)
                       : Request.GetResponse().GetResponseStream();
        }
开发者ID:debop,项目名称:NFramework,代码行数:31,代码来源:XmlHttpClient.cs

示例6: Compress

 /// <summary>
 /// 지정된 스트림을 압축합니다.
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public virtual byte[] Compress(Stream input) {
     input.ShouldNotBeNull("input");
     return Compress(input.ToBytes());
 }
开发者ID:debop,项目名称:NFramework,代码行数:9,代码来源:CompressAdapter.cs

示例7: DecompressAsync

        /// <summary>
        /// 원본 스트림을 압축 해제하여, 대상 스트림에 씁니다.
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <param name="targetStream"></param>
        public virtual void DecompressAsync(Stream sourceStream, Stream targetStream) {
            sourceStream.ShouldNotBeNull("sourceStream");
            targetStream.ShouldNotBeNull("destinationStream");

            var decompresedBytes = Decompress(sourceStream.ToBytes());
            targetStream.WriteAsync(decompresedBytes, 0, decompresedBytes.Length);
            targetStream.SetStreamPosition();
        }
开发者ID:debop,项目名称:NFramework,代码行数:13,代码来源:CompressAdapter.cs

示例8: Save

        /// <summary>
        /// <paramref name="stream"/>을 읽어, <paramref name="filepath"/>의 파일에 저장합니다.
        /// 해당 파일이 존재하면 겹쳐 쓰거나 추가를 할 수 있습니다. 파일이 없으면 새로 생성합니다. 
        /// </summary>
        /// <param name="filepath">대상 파일 경로</param>
        /// <param name="stream">저장할 내용</param>
        /// <param name="overwrite">겹쳐쓰기 여부</param>
        public static void Save(string filepath, Stream stream, bool overwrite) {
            filepath.ShouldNotBeWhiteSpace("filepath");
            stream.ShouldNotBeNull("stream");

            if(IsDebugEnabled)
                log.Debug("스트림 내용을 파일에 저장합니다... filepath=[{0}], overwrite=[{1}]", filepath, overwrite);

            stream.SetStreamPosition(0);

            if(overwrite && FileExists(filepath)) {
                if(IsDebugEnabled)
                    log.Debug("기존 파일이 존재하고, 겹쳐쓰기를 해야 하므로, 기존 파일을 삭제합니다. filepath=[{0}]", filepath);

                DeleteFile(filepath);
            }

            //using(var fs = File.Open(filepath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
            //using(var bs = new BufferedStream(fs))
            using(var bs = GetBufferedFileStream(filepath, FileOpenMode.ReadWrite)) {
                var buffer = new byte[DEFAULT_BUFFER_SIZE];

                int readCount;
                while((readCount = stream.Read(buffer, 0, DEFAULT_BUFFER_SIZE)) > 0) {
                    bs.Write(buffer, 0, readCount);
                }
                bs.Flush();
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:35,代码来源:FileTool.cs

示例9: CopyStreamIterator

        private static IEnumerable<Task> CopyStreamIterator(Stream input, Stream output) {
            input.ShouldNotBeNull("input");
            output.ShouldNotBeNull("output");

            if(IsDebugEnabled)
                log.Debug("입출력 스트림 간의 데이타 복사를 수행하는 Task의 열거자를 생성합니다...");

            // 두개의 버퍼를 만든다.
            // 하나는 읽기 전용, 하나는 쓰기 전용. 계속해서 두개의 버퍼 내용을 스위칭하여 사용한다.
            //
            var buffers = new[] { new byte[BufferSize], new byte[BufferSize] };
            var filledBufferNo = 0;
            Task writeTask = null;

            while(true) {
                // 비동기 stream 읽기 작업
                var readTask = input.ReadAsync(buffers[filledBufferNo], 0, buffers[filledBufferNo].Length);

                if(writeTask == null) {
                    yield return readTask;

                    // Wait() 호출은 Task 작업 중에 예외발생 시, 예외를 전파시키기 위해서이다.
                    readTask.Wait();
                }
                else {
                    var tasks = new[] { readTask, writeTask };
                    yield return Task.Factory.WhenAll(tasks);

                    // Wait() 호출은 Task 작업 중에 예외발생시, 예외를 전파시키기 위해서이다.
                    Task.WaitAll(tasks);
                }

                // 더 이상 읽을 데이타가 없다면 중지한다.
                if(readTask.Result <= 0)
                    break;

                // 읽어들인 버퍼 내용을 output stream에 비동기적으로 씁니다.
                writeTask = output.WriteAsync(buffers[filledBufferNo], 0, readTask.Result);

                // Swap buffers
                filledBufferNo ^= 1;
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:43,代码来源:StreamAsync.cs

示例10: Download

        /// <summary>
        /// 원격 파일을 다운받아 지정된 스트림에 쓴다.
        /// </summary>
        /// <param name="remoteFilename">원격 파일 전체 경로 (예: /Users/debop/readme.txt)</param>
        /// <param name="localStream">원격파일 정보를 저장할 Stream 객체</param>
        /// <returns>다운로드 여부</returns>
        public bool Download(string remoteFilename, Stream localStream) {
            localStream.ShouldNotBeNull("localStream");

            if(IsDebugEnabled)
                log.Debug("원격 파일을 다운로드 받아 localStream에 씁니다.... remoteFilename=[{0}]", remoteFilename);

            remoteFilename = AdjustRemoteFilename(remoteFilename);
            var uri = Hostname + remoteFilename;

            try {
                using(var responseStream = GetDownloadResponseStream(uri)) {
                    byte[] buffer = new byte[FTP_FILE_BUFFER];
                    int readCount;

                    do {
                        readCount = responseStream.Read(buffer, 0, FTP_FILE_BUFFER);
                        localStream.Write(buffer, 0, readCount);
                    } while(readCount > 0);

                    // localStream.Flush();
                }

                if(IsDebugEnabled)
                    log.Debug("Download the remote file is success. remoteFilename=[{0}]", remoteFilename);

                return true;
            }
            catch(Exception ex) {
                if(log.IsWarnEnabled) {
                    log.Warn("Fail to download the remote file. remoteFilename=[{0}]", remoteFilename);
                    log.Warn(ex);
                }

                return false;
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:42,代码来源:FtpClient.cs

示例11: UploadTask

        /// <summary>
        /// <paramref name="ftpClient"/>를 이용하여, 로컬 파일 스트림을 FTP 서버로 Upload 합니다.
        /// </summary>
        /// <param name="ftpClient"></param>
        /// <param name="localStream"></param>
        /// <param name="remoteFilename"></param>
        /// <returns></returns>
        public static Task<bool> UploadTask(this FtpClient ftpClient, Stream localStream, string remoteFilename) {
            if(IsDebugEnabled)
                log.Debug("FTP 서버로 스트림을 비동기 방식으로 업로드합니다... RemoteFile=[{0}]", remoteFilename);

            localStream.ShouldNotBeNull("localStream");
            remoteFilename = ftpClient.AdjustRemoteFilename(remoteFilename);

            var uri = ftpClient.Hostname + remoteFilename;

            return
                GetRequestStreamTask(ftpClient, uri, WebRequestMethods.Ftp.UploadFile)
                    .ContinueWith(task => {
                                      localStream.CopyStreamToStream(task.Result);
                                      task.Result.Close();

                                      if(IsDebugEnabled)
                                          log.Debug("FTP 서버로 파일을 업로드를 완료했습니다. RemoteFile=[{0}]", remoteFilename);

                                      return true;
                                  },
                                  TaskContinuationOptions.ExecuteSynchronously);
        }
开发者ID:debop,项目名称:NFramework,代码行数:29,代码来源:FtpAsync.cs

示例12: CompressAsync

        /// <summary>
        /// 원본 스트림을 압축하여, 대상 스트림에 씁니다.
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <param name="destinationStream"></param>
        public virtual void CompressAsync(Stream sourceStream, Stream destinationStream) {
            sourceStream.ShouldNotBeNull("sourceStream");
            destinationStream.ShouldNotBeNull("destinationStream");

            var compressedBytes = Compress(sourceStream.ToBytes());
            destinationStream.WriteAsync(compressedBytes, 0, compressedBytes.Length);
        }
开发者ID:debop,项目名称:NFramework,代码行数:12,代码来源:CompressAdapter.cs

示例13: DownloadFile

        public static void DownloadFile(this IMongoRepository repository, Stream stream, MongoGridFSFileInfo fileInfo) {
            stream.ShouldNotBeNull("stream");
            fileInfo.ShouldNotBeNull("fileinfo");

            repository.GridFS.Download(stream, fileInfo);
        }
开发者ID:debop,项目名称:NFramework,代码行数:6,代码来源:MongoRepository.GridFS.cs

示例14: ReadIterator

        private static IEnumerable<Task> ReadIterator(Stream input, int bufferSize, Action<byte[], int> bufferAvailable) {
            input.ShouldNotBeNull("input");
            bufferSize.ShouldBePositive("bufferSize");
            bufferAvailable.ShouldNotBeNull("bufferAvailable");

            var buffer = new byte[bufferSize];

            while(true) {
                var readTask = input.ReadAsync(buffer, 0, buffer.Length);
                yield return readTask;

                if(readTask.Result <= 0)
                    break;

                bufferAvailable(buffer, readTask.Result);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:17,代码来源:StreamAsync.cs

示例15: DownloadTask

        /// <summary>
        /// FTP 서버에 있는 원격 파일을 다운로드하여, <paramref name="localStream"/>에 씁니다.
        /// </summary>
        /// <param name="ftpClient"></param>
        /// <param name="remoteFilename"></param>
        /// <param name="localStream"></param>
        /// <returns></returns>
        public static Task<bool> DownloadTask(this FtpClient ftpClient, string remoteFilename, Stream localStream) {
            localStream.ShouldNotBeNull("localStream");

            if(IsDebugEnabled)
                log.Debug("원격 파일을 다운로드 받는 작업을 생성합니다... remoteFilename=[{0}]", remoteFilename);

            remoteFilename = ftpClient.AdjustRemoteFilename(remoteFilename);
            var uri = ftpClient.Hostname + remoteFilename;

            return
                ftpClient
                    .GetResponseStreamTask(uri, WebRequestMethods.Ftp.DownloadFile)
                    .ContinueWith(task => {
                                      task.Result.CopyStreamToStream(localStream);
                                      task.Result.Close();

                                      if(IsDebugEnabled)
                                          log.Debug("원격 파일 다운로드가 완료되었습니다. remoteFilename=[{0}]", remoteFilename);

                                      return true;
                                  },
                                  TaskContinuationOptions.ExecuteSynchronously);
        }
开发者ID:debop,项目名称:NFramework,代码行数:30,代码来源:FtpAsync.cs


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