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


C# GZipOutputStream.Flush方法代码示例

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


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

示例1: TestGZip

        public void TestGZip()
        {
            MemoryStream ms = new MemoryStream();
            GZipOutputStream outStream = new GZipOutputStream(ms);

            byte[] buf = new byte[100000];
            System.Random rnd = new Random();
            rnd.NextBytes(buf);

            outStream.Write(buf, 0, buf.Length);
            outStream.Flush();
            outStream.Finish();

            ms.Seek(0, SeekOrigin.Begin);

            GZipInputStream inStream = new GZipInputStream(ms);
            byte[] buf2 = new byte[buf.Length];
            int    pos  = 0;
            while (true) {
                int numRead = inStream.Read(buf2, pos, 4096);
                if (numRead <= 0) {
                    break;
                }
                pos += numRead;
            }

            for (int i = 0; i < buf.Length; ++i) {
                Assertion.AssertEquals(buf2[i], buf[i]);
            }
        }
开发者ID:foresightbrand,项目名称:brandqq,代码行数:30,代码来源:GZipTests.cs

示例2: TestGZip

		public void TestGZip()
		{
			MemoryStream ms = new MemoryStream();
			GZipOutputStream outStream = new GZipOutputStream(ms);

			byte[] buf = new byte[100000];
			System.Random rnd = new Random();
			rnd.NextBytes(buf);

			outStream.Write(buf, 0, buf.Length);
			outStream.Flush();
			outStream.Finish();

			ms.Seek(0, SeekOrigin.Begin);

			GZipInputStream inStream = new GZipInputStream(ms);
			byte[] buf2 = new byte[buf.Length];
			int currentIndex = 0;
			int count = buf2.Length;
			
			while (true) {
				int numRead = inStream.Read(buf2, currentIndex, count);
				if (numRead <= 0) {
					break;
				}
				currentIndex += numRead;
				count -= numRead;
			}

			Assert.AreEqual(0, count);
			
			for (int i = 0; i < buf.Length; ++i) {
				Assert.AreEqual(buf2[i], buf[i]);
			}
		}
开发者ID:rollingthunder,项目名称:slsharpziplib,代码行数:35,代码来源:GZipTests.cs

示例3: CtorErrMsg

        public static byte[] CtorErrMsg(string msg, NameValueCollection requestParam)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                //包总长度
                int len = 0;
                long pos = 0;
                //包总长度,占位
                WriteValue(ms, len);
                int actionid = Convert.ToInt32(requestParam["actionid"]);
                //StatusCode
                WriteValue(ms, 10001);
                //msgid
                WriteValue(ms, Convert.ToInt32(requestParam["msgid"]));
                WriteValue(ms, msg);
                WriteValue(ms, actionid);
                WriteValue(ms, "st");
                //playerdata
                WriteValue(ms, 0);
                //固定0
                WriteValue(ms, 0);
                ms.Seek(pos, SeekOrigin.Begin);
                WriteValue(ms, (int)ms.Length);

                using (var gms = new MemoryStream())
                using (var gzs = new GZipOutputStream(gms))
                {
                    gzs.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    gzs.Flush();
                    gzs.Close();
                    return gms.ToArray();
                }
            }
        }
开发者ID:0jpq0,项目名称:Scut,代码行数:34,代码来源:RequestParse.cs

示例4: compress_gzip

 /// <summary>
 /// Compresses byte array using gzip
 /// Compressed data is returned as a byte array
 /// </summary>
 /// <param name="inBytes">The bytes to compress</param>
 public static byte[] compress_gzip(byte[] inBytes)
 {
     MemoryStream ContentsGzippedStream = new MemoryStream();	//create the memory stream to hold the compressed file
     Stream s = new GZipOutputStream(ContentsGzippedStream);		//create the gzip filter
     s.Write(inBytes, 0, inBytes.Length);				        //write the file contents to the filter
     s.Flush();													//make sure everythings ready
     s.Close();													//close and write the compressed data to the memory stream
     return ContentsGzippedStream.ToArray();
 }
开发者ID:andyhebear,项目名称:extramegablob,代码行数:14,代码来源:Helpers.cs

示例5: returnZippedbyteArray

        public static byte[] returnZippedbyteArray(string stringToZip)
        {
            MemoryStream memStream = new MemoryStream();
            Stream compressedStream = new GZipOutputStream(memStream);
            byte[] byteArrayToZip = Encoding.UTF8.GetBytes(stringToZip.ToCharArray());

            compressedStream.Write(byteArrayToZip ,0,byteArrayToZip.Length);
            compressedStream.Flush();
            compressedStream.Close();
            return memStream.ToArray();
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:11,代码来源:zip.cs

示例6: Write

		public override void Write(byte[] value)
		{
			var compressedStream = new MemoryStream();
			try
			{
				using (var inputStream = new MemoryStream(value))
				{
					using (var compressionStream = new GZipOutputStream(compressedStream))
					{
						compressionStream.SetLevel(9);
						inputStream.CopyTo(compressionStream);
						compressionStream.Flush();
					}
				}

				var compressedData = compressedStream.ToArray();
				_lock.Wait();

				using (var outputStream = File.OpenWrite(_filePath))
				{
					outputStream.Position = outputStream.Length;
					outputStream.Write(compressedData, 0, compressedData.Length);
					outputStream.Flush();
				}
			}
			finally
			{
				compressedStream.Dispose();
				_lock.Release();
			}

			var info = new FileInfo(_filePath);
			var bufferSize = info.Length;
			if (bufferSize > MaxBufferSize)
			{
				Flush();
			}
		}
开发者ID:smartpcr,项目名称:bigdata2,代码行数:38,代码来源:DiskEventStore.cs

示例7: Create

        /// <summary>
        /// Creates the Transformation Block to GZip compress.
        /// </summary>
        /// <param name="level">The compression level.</param>
        /// <param name="options">The options.</param>
        /// <returns>TransformBlock&lt;System.Byte[], System.Byte[]&gt;.</returns>
        public static TransformBlock<byte[], byte[]> Create(int level, ExecutionDataflowBlockOptions options)
        {
            return new TransformBlock<byte[], byte[]>(data =>
            {
                using (var output = new MemoryStream())
                {
                    using (var input = new MemoryStream(data))
                    using (var compression = new GZipOutputStream(output))
                    using (Logger.BeginTimedOperation("GZipOutputStream", null, LogEventLevel.Debug))
                    {
                        compression.SetLevel(level);
                        input.CopyTo(compression);
                        compression.Flush();
                    }

                    var result = output.ToArray();

                    Logger.Debug("Compressed {InputSize} bytes to {OutputSize} ({Compression:00}%)", data.Length, result.Length, result.Length * 100M / data.Length);

                    return result;
                }

            }, options);
        }
开发者ID:bradsjm,项目名称:AprsEventHubDemo,代码行数:30,代码来源:GZip.cs

示例8: ZipString

        /// zip a utf8 string using gzip into a base64 encoded string
        public static string ZipString(string ATextToCompress)
        {
            Byte[] originalText = Encoding.UTF8.GetBytes(ATextToCompress);

            MemoryStream memoryStream = new MemoryStream();
            GZipOutputStream gzStream = new GZipOutputStream(memoryStream);

            gzStream.Write(originalText, 0, originalText.Length);
            gzStream.Flush();
            gzStream.Finish();
            memoryStream.Position = 0;

            Byte[] compressedBuffer = new byte[memoryStream.Length];
            memoryStream.Read(compressedBuffer, 0, compressedBuffer.Length);

            gzStream.Close();

            return Convert.ToBase64String(compressedBuffer);
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:20,代码来源:PackTools.cs

示例9: Run

        public override async Task<bool> Run()
        {
            try
            {
                var ftpClient = new FtpRawLogClient(JobEventSource.Log, _ftpUsername, _ftpPassword);
                var azureClient = new CloudBlobRawLogClient(JobEventSource.Log, _cloudStorageAccount);

                // Collect directory listing.
                IEnumerable<RawLogFileInfo> rawLogFiles = await ftpClient.GetRawLogFiles(_ftpServerUri);

                // Prepare cloud storage blob container.
                var cloudBlobContainer = await azureClient.CreateContainerIfNotExistsAsync(_cloudStorageContainerName);

                foreach (var rawLogFile in rawLogFiles)
                {
                    try
                    {
                        // Only process the raw log files matching the target CDN platform and account number.
                        if (_azureCdnPlatform == rawLogFile.AzureCdnPlatform && _azureCdnAccountNumber.Equals(rawLogFile.AzureCdnAccountNumber, StringComparison.InvariantCultureIgnoreCase))
                        {
                            bool alreadyUploaded = false;
                            bool uploadSucceeded = false;
                            Uri rawLogUri = rawLogFile.Uri;

                            // Check if this is an already renamed file.
                            if (rawLogFile.IsPendingDownload)
                            {
                                // Check if the file has already been uploaded to blob storage.
                                alreadyUploaded = await azureClient.CheckIfBlobExistsAsync(cloudBlobContainer, rawLogFile);
                            }
                            else
                            {
                                // Rename the file on the origin to ensure we're not locking a file that still can be written to.
                                rawLogUri = await ftpClient.RenameAsync(rawLogFile, rawLogFile.FileName + FileExtensions.Download);

                                if (rawLogUri == null)
                                {
                                    // Failed to rename the file. Leave it and try again later.
                                    continue;
                                }
                            }

                            if (!alreadyUploaded)
                            {
                                // open the raw log from FTP
                                using (var rawLogStream = await ftpClient.OpenReadAsync(rawLogUri))
                                using (var rawLogStreamInMemory = new MemoryStream())
                                {
                                    // copy the raw, compressed stream to memory - FTP does not like reading line by line
                                    await rawLogStream.CopyToAsync(rawLogStreamInMemory);
                                    rawLogStreamInMemory.Position = 0;

                                    // process the raw, compressed memory stream
                                    using (var rawGzipStream = new GZipInputStream(rawLogStreamInMemory))
                                    {
                                        try
                                        {
                                            // ensure the .download suffix is trimmed away
                                            var fileName = rawLogFile.FileName.Replace(".download", string.Empty);

                                            Trace.TraceInformation("Uploading file '{0}'.", fileName);
                                            JobEventSource.Log.BeginningBlobUpload(rawLogFile.Uri.ToString());

                                            // open the resulting cleaned blob and stream modified entries
                                            // note the missing using() statement so that we can skip committing if an exception occurs
                                            var resultLogStream = await azureClient.OpenBlobForWriteAsync(cloudBlobContainer, rawLogFile, fileName);
                                            try
                                            {
                                                using (var resultGzipStream = new GZipOutputStream(resultLogStream))
                                                {
                                                    resultGzipStream.IsStreamOwner = false;

                                                    ProcessLogStream(rawGzipStream, resultGzipStream);

                                                    resultGzipStream.Flush();
                                                }

                                                // commit to blob storage
                                                resultLogStream.Commit();

                                                uploadSucceeded = true;
                                            }
                                            catch
                                            {
                                                resultLogStream = null;
                                                uploadSucceeded = false;
                                                throw;
                                            }

                                            Trace.TraceInformation("Finished uploading file '{0}' to '{1}'.", fileName, rawLogFile.Uri.AbsoluteUri);
                                            JobEventSource.Log.FinishingBlobUpload(rawLogFile.Uri.ToString());
                                        }
                                        catch (Exception exception)
                                        {
                                            Trace.TraceError(exception.ToString());
                                            JobEventSource.Log.FailedToUploadFile(rawLogFile.Uri.ToString(), exception.ToString());
                                        }
                                    }
                                }
                            }
//.........这里部分代码省略.........
开发者ID:joyhui,项目名称:NuGet.Jobs,代码行数:101,代码来源:Job.cs

示例10: TrailingGarbage

        public void TrailingGarbage()
        {
            /* ARRANGE */
            var ms = new MemoryStream();
            var outStream = new GZipOutputStream(ms);

            // input buffer to be compressed
            byte[] buf = new byte[100000];
            var rnd = new Random();
            rnd.NextBytes(buf);

            // compress input buffer
            outStream.Write(buf, 0, buf.Length);
            outStream.Flush();
            outStream.Finish();

            // generate random trailing garbage and add to the compressed stream
            byte[] garbage = new byte[4096];
            rnd.NextBytes(garbage);
            ms.Write(garbage, 0, garbage.Length);

            // rewind the concatenated stream
            ms.Seek(0, SeekOrigin.Begin);

            /* ACT */
            // decompress concatenated stream
            var inStream = new GZipInputStream(ms);
            byte[] buf2 = new byte[buf.Length];
            int currentIndex = 0;
            int count = buf2.Length;
            while (true) {
                int numRead = inStream.Read(buf2, currentIndex, count);
                if (numRead <= 0) {
                    break;
                }
                currentIndex += numRead;
                count -= numRead;
            }

            /* ASSERT */
            Assert.AreEqual(0, count);
            for (int i = 0; i < buf.Length; ++i) {
                Assert.AreEqual(buf2[i], buf[i]);
            }
        }
开发者ID:icsharpcode,项目名称:SharpZipLib,代码行数:45,代码来源:GZipTests.cs

示例11: GzipCompressDecompress

        public void GzipCompressDecompress()
        {
            for (int i = 100; i < 10000;i++ )
            {
                var str = new string('B', i) + "a";
                var outputStream = new MemoryStream();

                var zoutStream = new GZipOutputStream(outputStream);
                var buf = Encoding.UTF8.GetBytes(str);
                zoutStream.Write(buf, 0, buf.Length);

                zoutStream.Flush();
                zoutStream.Finish();
                outputStream.Seek(0, SeekOrigin.Begin);

                //var compressed = new StreamReader(ms).ReadToEnd();
                //ms.Seek(0, SeekOrigin.Begin);

                var inStream = new GZipInputStream(outputStream);

                var buf2 = new byte[buf.Length];
                int currentIndex = 0;
                int count = buf2.Length;

                while (true)
                {
                    int numRead = inStream.Read(buf2, currentIndex, count);
                    if (numRead <= 0)
                    {
                        break;
                    }
                    currentIndex += numRead;
                    count -= numRead;
                }
                Assert.AreEqual(0, count);

                for (var j = 0; j < buf.Length; ++j)
                {
                    Assert.AreEqual(buf2[j], buf[j]);
                }
            }
        }
开发者ID:siarheimilkevich,项目名称:VSSync,代码行数:42,代码来源:CsvParserTest.cs

示例12: CreateOrModifyCacheFile

        private void CreateOrModifyCacheFile(BinaryData cacheBinary, bool compress)
        {
            SN.File f = null;
            MemoryStream cacheStream = new MemoryStream();

            if (compress)
            {
                GZipOutputStream gzipStream = new GZipOutputStream(cacheStream);
                byte[] buff = Encoding.ASCII.GetBytes(this._content.ToCharArray());
                gzipStream.Write(buff, 0, buff.Length);
                gzipStream.Flush();
                gzipStream.Close();

                // set compressed binary
                byte[] compressedData = cacheStream.ToArray();
                cacheBinary.SetStream(new MemoryStream(compressedData));
            } else
                cacheBinary.SetStream(Tools.GetStreamFromString(_content));

            // gets cache file or creates a new one, the new stream will be saved in both cases
            if (!Node.Exists(FullCacheFilePath))
            {
				f = SN.File.CreateByBinary(this.CacheFolder, cacheBinary);
                f.Name = _cacheFile;
            }
            else
            {
				f = Node.Load<SN.File>(this.FullCacheFilePath);
                f.Binary = cacheBinary;
            }
            f.Save();

        }
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:33,代码来源:TinyMCEGzipHandler.cs

示例13: WriteWithoutCache

 private void WriteWithoutCache(HttpContext context)
 {
     GZipOutputStream gzipStream = new GZipOutputStream(context.Response.OutputStream);
     byte[] buff = GetEncoding.GetBytes(_content.ToCharArray());
     gzipStream.Write(buff, 0, buff.Length);
     gzipStream.Flush();
     gzipStream.Close();
 }
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:8,代码来源:TinyMCEGzipHandler.cs

示例14: CompressDataSet

        /// <summary>
        /// Compresses specified dataset with GZIP.
        /// </summary>
        /// <param name="ds">DataSet to compress.</param>
        /// <returns>Returns gzipped dataset xml data.</returns>
        private byte[] CompressDataSet(DataSet ds)
        {
            /* Mono won't support it
            MemoryStream ms = new MemoryStream();
            ds.WriteXml(ms);
            
            MemoryStream retVal = new MemoryStream();
            GZipStream gzip = new GZipStream(retVal,CompressionMode.Compress);

            byte[] dsBytes = ms.ToArray();
            gzip.Write(dsBytes,0,dsBytes.Length);
            gzip.Flush();
            gzip.Dispose();

            return retVal.ToArray();
            */

            MemoryStream ms = new MemoryStream();
            ds.WriteXml(ms);
            
            MemoryStream retVal = new MemoryStream();
            GZipOutputStream gzip = new GZipOutputStream(retVal);

            byte[] dsBytes = ms.ToArray();
            gzip.Write(dsBytes,0,dsBytes.Length);
            gzip.Flush();
            gzip.Dispose();

            return retVal.ToArray();
        }
开发者ID:dioptre,项目名称:nkd,代码行数:35,代码来源:MonitoringServerSession.cs

示例15: createResource

        private static string createResource(   Dictionary<string,string> resources,
            MemoryStream sourceCompressedStream,
            string uncompressedFileLocation,
            string friendlyName,
            string codeOutputDirectory,
            string subdirectory)
        {
            string location = uncompressedFileLocation;
            string suffix = "";
            bool useCompressed = false;
            string complocation;
            if (string.IsNullOrEmpty(codeOutputDirectory))
            {
                complocation = Path.GetTempFileName();
                File.Move(complocation, complocation + ".gz");
                complocation = complocation + ".gz";
            }
            else
            {
                var dir = codeOutputDirectory;
                if (!string.IsNullOrEmpty(subdirectory))
                    dir = Path.Combine(codeOutputDirectory, subdirectory);
                if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);
                complocation = Path.Combine(dir, Path.GetFileName(location) + ".gz");
            }

            try
            {
                int totalRead = 0;
                using (FileStream fs = new FileStream(complocation, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                {
                    if (sourceCompressedStream == null)
                    {
                        using (Stream fi = new FileStream(location, FileMode.Open, FileAccess.Read, FileShare.Read))
                        using (GZipOutputStream com = new GZipOutputStream(fs, 65536))
                        {
                            com.IsStreamOwner = false;

                            byte[] bytes = new byte[4096];
                            int n;
                            while ((n = fi.Read(bytes, 0, bytes.Length)) != 0)
                            {
                                com.Write(bytes, 0, n);
                                totalRead += n;
                            }
                            com.Flush();
                        }
                    }
                    else
                    {
                        sourceCompressedStream.WriteTo(fs);

                        totalRead = (int)fs.Length;
                    }

                    fs.Flush();
                    if (fs.Length > totalRead)
                    {
                        // GZip sucks!
                        File.Delete(complocation);
                    }
                    else
                    {
                        location = complocation;
                        suffix = ".gz";
                        useCompressed = true;
                    }
                }

            }
            catch
            {
                // Compression failed, but we don't care and use uncompressed version instead
                try
                {
                    File.Delete(complocation);
                }
                catch
                {
                }
            }

            // param.EmbeddedResources works incorrectly :(
            resources[location] = friendlyName + suffix;
            if (useCompressed)
                return complocation;
            return null;
        }
开发者ID:xsharper,项目名称:xsharper,代码行数:89,代码来源:CSharpCompiler.cs


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