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


C# MemoryStream.Reset方法代码示例

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


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

示例1: CreatePdf

        /// <summary>
        /// Merges a row tree with a PDF document containing form fields.
        /// </summary>
        public static void CreatePdf(
            MergeRowTree rowTree, bool ensureAllFieldsHaveValues, MemoryStream sourcePdfStream, Stream destinationStream,
            bool useLegacyBehaviorOfIgnoringInvalidFields = false)
        {
            var streams = new List<Stream>();
            try {
                foreach( var row in rowTree.Rows ) {
                    var stream = new MemoryStream();
                    streams.Add( stream );

                    using( var sourcePdfMemoryStreamCopy = new MemoryStream() ) {
                        // Aspose has decided that in the new Facades PDF library, they will close your source stream for you when you call doc.Save.
                        sourcePdfStream.Reset();
                        sourcePdfStream.CopyTo( sourcePdfMemoryStreamCopy );

                        var doc = new Aspose.Pdf.Facades.Form( sourcePdfMemoryStreamCopy );
                        foreach( var mergeField in doc.FieldNames.Where( mergeField => !mergeField.StartsWith( "noMerge" ) ) ) {
                            var mergeValue = row.Values.SingleOrDefault( v => v.Name == mergeField );
                            if( mergeValue == null ) {
                                if( useLegacyBehaviorOfIgnoringInvalidFields )
                                    continue;
                                throw new MailMergingException( string.Format( "PDF document contains a merge field ({0}) that does not exist.", mergeField ) );
                            }

                            var mergeValueAsString = mergeValue as MergeValue<string>;
                            string value = null;
                            if( mergeValueAsString != null )
                                value = mergeValueAsString.Evaluate( ensureAllFieldsHaveValues );
                            if( value == null )
                                throw new MailMergingException( "Merge field " + mergeValue.Name + " evaluates to an unsupported type." );

                            doc.FillField( mergeValue.Name, value );
                        }
                        doc.Save( stream );
                    }
                }

                if( streams.Any() )
                    PdfOps.ConcatPdfs( streams, destinationStream );
            }
            finally {
                foreach( var i in streams )
                    i.Dispose();
            }
        }
开发者ID:enduracode,项目名称:enterprise-web-library,代码行数:48,代码来源:MergeOps.cs

示例2: Decode

        public static string Decode(string s, bool convertPlus, Encoding charset)
        {
            if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1)) {
                return s;
            }

            StringBuilder result = new StringBuilder(s.Length);
            MemoryStream @out = new MemoryStream();
            for (int i = 0; i < s.Length;) {
                char c = s[i];
                if (c == '%') {
                    do {
                        if (i + 2 >= s.Length) {
                            throw new ArgumentException("Incomplete % sequence at: " + i);
                        }
                        int d1 = HexToInt(s[i + 1]);
                        int d2 = HexToInt(s[i + 2]);
                        if (d1 == -1 || d2 == -1) {
                            throw new ArgumentException("Invalid % sequence " + s.Substring(i, 3) + " at " + i);
                        }
                        @out.WriteByte(unchecked((byte)((d1 << 4) + d2)));
                        i += 3;
                    } while (i < s.Length && s[i] == '%');
                    result.Append(charset.GetString(@out.ToArray()));
                    @out.Reset();
                }
                else {
                    if (convertPlus && c == '+') {
                        c = ' ';
                    }
                    result.Append(c);
                    i++;
                }
            }

            return result.ToString();
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:37,代码来源:URIUtils.cs

示例3: UpdateItemManifest

        /// <summary>
        /// Stores item manifest in zip package's comments
        /// </summary>
        private void UpdateItemManifest()
        {
            if (this.TempZipFile)
                throw new ApplicationException("ZipPackage is read-only when reading from temp directory");

            if (this.ItemManifest.Items.Count == 0)
                throw new ApplicationException("No items to add to package manifest");

            var manifestXml = XmlSerializer.SerializeXml(this.ItemManifest);

            using (var ms = new MemoryStream())
            {
                using (ZipFile zip = this.Items.Length == 0 ? new ZipFile() : ZipFile.Read(this.Items.Reset()))
                {
                    if (zip.ContainsEntry("manifest.xml"))
                        zip.UpdateEntry("manifest.xml", XmlSerializer.StringToUTF8ByteArray(manifestXml));
                    else
                        zip.AddEntry("manifest.xml", XmlSerializer.StringToUTF8ByteArray(manifestXml));

                    zip.Save(ms);
                }

                this.Items = new MemoryStream();
                ms.Reset().CopyTo(this.Items);
            }
        }
开发者ID:cnewham,项目名称:CSharp-Helpers,代码行数:29,代码来源:ZipPackage.cs

示例4: Extract

        /// <summary>
        /// Returns an open stream from Items for the named item
        /// </summary>
        /// <param name="itemName"></param>
        /// <returns></returns>
        public Stream Extract(string itemName)
        {
            Stream ms = new MemoryStream();

            if (this.TempZipFile)
            {
                using (var file = new FileStream(this.TempZipFilePath, FileMode.Open))
                {
                    file.CopyTo(ms);
                }
            }
            else
            {
                using (ZipFile zip = ZipFile.Read(this.Items.Reset()))
                {
                    ZipEntry entry = zip[itemName];
                    if (entry != null)
                        entry.Extract(ms);
                }
            }

            return ms.Reset();
        }
开发者ID:cnewham,项目名称:CSharp-Helpers,代码行数:28,代码来源:ZipPackage.cs

示例5: Add

        /// <summary>
        /// Adds an item to Items
        /// </summary>
        /// <param name="itemType"></param>
        /// <param name="item"></param>
        /// <param name="itemName"></param>
        /// <returns></returns>
        public void Add(ZipPackageItemType itemType, string itemName, Stream item)
        {
            if (this.TempZipFile)
                throw new ApplicationException("ZipPackage is read-only when reading from temp directory");

            using (var ms = new MemoryStream())
            {
                using (ZipFile zip = this.Items.Length == 0 ? new ZipFile() : ZipFile.Read(this.Items.Reset()))
                {
                    zip.AddEntry(itemName, item.Reset());
                    zip.Save(ms);
                }

                this.Items = new MemoryStream();
                ms.Reset().CopyTo(this.Items);
            }

            this.ItemManifest.Items.Add(new OfflineZipPackageItem<string, ZipPackageItemType>(itemName, itemType));

            this.UpdateItemManifest();
        }
开发者ID:cnewham,项目名称:CSharp-Helpers,代码行数:28,代码来源:ZipPackage.cs

示例6: Test

        internal static void Test()
        {
            // NOTE: This path is probably wrong, and should not be hard-coded.
            const string sourceFolderPath = @"C:\Red Stapler Vault\Supporting Files\Standard Library\Standard Library\MailMerging";

            var outputFolderPath = TestStatics.OutputFolderPath;
            IoMethods.DeleteFolder( outputFolderPath );

            // Create and extract empty zip file
            var emptyFolderPath = EwlStatics.CombinePaths( outputFolderPath, "Empty" );
            Directory.CreateDirectory( emptyFolderPath );
            var emptyZipPath = EwlStatics.CombinePaths( outputFolderPath, "empty.zip" );
            ZipFolderAsFile( emptyFolderPath, emptyZipPath );
            using( var memoryStream = new MemoryStream() ) {
                ZipFolderAsStream( emptyFolderPath, memoryStream );
                memoryStream.Reset();
                UnZipStreamIntoFolder( memoryStream, EwlStatics.CombinePaths( outputFolderPath, "Empty from stream" ) );
            }

            // File-based
            var zipFilePath = EwlStatics.CombinePaths( outputFolderPath, "file.zip" );
            var extractedPath = EwlStatics.CombinePaths( outputFolderPath, "Extracted from File" );
            ZipFolderAsFile( sourceFolderPath, zipFilePath );
            UnZipFileAsFolder( zipFilePath, extractedPath );

            // Byte-array-based
            var bytes = ZipFolderAsByteArray( sourceFolderPath );
            var byteZipFilePath = EwlStatics.CombinePaths( outputFolderPath, "fileFromBytes.zip" );
            File.WriteAllBytes( byteZipFilePath, bytes );
            UnZipByteArrayAsFolder( File.ReadAllBytes( byteZipFilePath ), EwlStatics.CombinePaths( outputFolderPath, "Extracted from Byte Array" ) );

            // Stream-based
            var streamedFilePath = EwlStatics.CombinePaths( outputFolderPath, "fileFromStream.zip" );
            using( var fs = new FileStream( streamedFilePath, FileMode.Create ) )
                ZipFolderAsStream( sourceFolderPath, fs );

            var streamedExtractedPath = EwlStatics.CombinePaths( outputFolderPath, "Extracted from Stream" );
            using( var memoryStream = new MemoryStream() ) {
                ZipFolderAsStream( sourceFolderPath, memoryStream );
                memoryStream.Reset();
                UnZipStreamIntoFolder( memoryStream, streamedExtractedPath );
            }

            using( var fs = File.OpenRead( streamedFilePath ) ) {
                var files = UnZipStreamAsFileObjects( fs );
                ZipFileObjectsAsStream( files, File.OpenWrite( EwlStatics.CombinePaths( outputFolderPath, "fileFromStreamedFileObjects.zip" ) ) );
            }
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:48,代码来源:ZipOps.cs

示例7: Main

        static void Main(string[] args)
        {
            {
                var ms = new MemoryStream();
                var t1 = new Packtest();
                ms.Reset();
                t1.Field9 = null;
                t1.Pack(ms);
                ms.Reset();
                t1.Unpack(ms);
            }
            return;

            var test1 = new SpeedTest(delegate()
            {
                var ms = new MemoryStream();
                var t1 = new Packtest();
                ms.Reset();
                t1.Pack(ms);
                ms.Reset();
                t1.Unpack(ms);
            });

            var test2 = new SpeedTest(delegate()
            {
                var ms = new MemoryStream();
                var t2 = new Packtest2();
                ms.Reset();
                t2.Pack(ms);
                ms.Reset();
                t2.Unpack(ms);
            });

            test2.Test();
            test1.Test();

            Console.WriteLine("My serialize class");
            Console.WriteLine("Min: {0}ms", test1.Min);
            Console.WriteLine("Avg: {0}ms", test1.Average);
            Console.WriteLine("Max: {0}ms", test1.Max);
            Console.WriteLine();
            Console.WriteLine("Binaryreader/writer");
            Console.WriteLine("Min: {0}ms", test2.Min);
            Console.WriteLine("Avg: {0}ms", test2.Average);
            Console.WriteLine("Max: {0}ms", test2.Max);

            Console.ReadKey();
        }
开发者ID:FPCollab,项目名称:General,代码行数:48,代码来源:Program.cs


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