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


C# MemoryStream.WriteTo方法代码示例

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


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

示例1: Main

        public static void Main(string[] args)
        {
            try
            {
                string assName = args [0];
                string outFile = Path.GetDirectoryName (Assembly.GetEntryAssembly ().CodeBase).Substring (5) + "/" + Path.GetFileName (args [0]) + ".xml";
                string htmlFile = outFile.Replace (".xml", ".html");

                XmlSerializer xs = new XmlSerializer (typeof(ReflectedContainer));
                ReflectedAssembly ass = new ReflectedAssembly (assName);

                Console.Write (string.Format ("Output XML reflection for {0} (to console and to {1})\n [Y/n] ?", assName, outFile));
                ConsoleKey input = Console.ReadKey ().Key;
                if (input != ConsoleKey.N)
                {
                    Console.WriteLine ("\n");
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (XmlWriter xw = XmlWriter.Create (ms, XWSettings))
                        {
                            xs.Serialize (xw, new ReflectedContainer () { Assembly = ass });
                        }

                        if (File.Exists (outFile))
                            File.Delete (outFile);
                        using (Stream fs = File.OpenWrite (outFile), cs = Console.OpenStandardOutput ())
                        {
                            ms.WriteTo (fs);
                            ms.WriteTo (cs);
                        }

            //						if (File.Exists (htmlFile))
            //							File.Delete (htmlFile);
            //						using (Stream hs = File.OpenWrite (htmlFile))
            //						{
            //							using (XmlWriter xw = XmlWriter.Create(hs, XWSettings))
            //							{
            //								foreach (ReflectedType rt in ass.Types)
            //									rt.WriteHtml(xw);
            //							}
            //						}
                    }
                }
                else
                    Console.WriteLine ("Cancelled, exiting..");
            }
            catch (Exception ex)
            {
                Console.WriteLine ("! Exception : " + ex.ToString () + " : " + ex.Message);
            }
            finally
            {

            }
        }
开发者ID:jbowwww,项目名称:Reflector,代码行数:55,代码来源:Main.cs

示例2: Main

        static void Main(string[] args)
        {
            MemoryStream ms = new MemoryStream();

            StreamWriter sw = new StreamWriter(ms);

            Console.WriteLine("Enter 'quit' on a blank line to exit.");
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "quit")
                    break;
                sw.WriteLine(input);
            }
            sw.Flush();

            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForAssembly();

            IsolatedStorageFileStream fs = new IsolatedStorageFileStream("output.txt", FileMode.Create, isoStore);
            ms.WriteTo(fs);

            sw.Close();
            ms.Close();
            fs.Close();

            IsolatedStorageFileStream tr = new IsolatedStorageFileStream("output.txt", FileMode.Open, isoStore);
            StreamReader sr = new StreamReader(tr);
            Console.Write(sr.ReadToEnd());
            sr.Close();
            tr.Close();
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:31,代码来源:Program.cs

示例3: Run

        public static void Run()
        {
            // ExStart:ExtractImagesStream
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Images();
            // Open input PDF
            PdfExtractor pdfExtractor = new PdfExtractor();
            pdfExtractor.BindPdf(dataDir+ "ExtractImages-Stream.pdf");

            // Extract images
            pdfExtractor.ExtractImage();
            // Get all the extracted images
            while (pdfExtractor.HasNextImage())
            {
                // Read image into memory stream
                MemoryStream memoryStream = new MemoryStream();
                pdfExtractor.GetNextImage(memoryStream);

                // Write to disk, if you like, or use it otherwise.
                FileStream fileStream = new
                FileStream(dataDir+ DateTime.Now.Ticks.ToString() + "_out.jpg", FileMode.Create);
                memoryStream.WriteTo(fileStream);
                fileStream.Close();
            }
            // ExEnd:ExtractImagesStream
        }
开发者ID:aspose-pdf,项目名称:Aspose.Pdf-for-.NET,代码行数:26,代码来源:ExtractImagesStream.cs

示例4: Encode

        /**
         * Encode this {@link OcspStatusRequest} to a {@link Stream}.
         * 
         * @param output
         *            the {@link Stream} to encode to.
         * @throws IOException
         */
        public virtual void Encode(Stream output)
        {
            if (mResponderIDList == null || mResponderIDList.Count < 1)
            {
                TlsUtilities.WriteUint16(0, output);
            }
            else
            {
                MemoryStream buf = new MemoryStream();
                for (int i = 0; i < mResponderIDList.Count; ++i)
                {
                    ResponderID responderID = (ResponderID)mResponderIDList[i];
                    byte[] derEncoding = responderID.GetEncoded(Asn1Encodable.Der);
                    TlsUtilities.WriteOpaque16(derEncoding, buf);
                }
                TlsUtilities.CheckUint16(buf.Length);
                TlsUtilities.WriteUint16((int)buf.Length, output);
                buf.WriteTo(output);
            }

            if (mRequestExtensions == null)
            {
                TlsUtilities.WriteUint16(0, output);
            }
            else
            {
                byte[] derEncoding = mRequestExtensions.GetEncoded(Asn1Encodable.Der);
                TlsUtilities.CheckUint16(derEncoding.Length);
                TlsUtilities.WriteUint16(derEncoding.Length, output);
                output.Write(derEncoding, 0, derEncoding.Length);
            }
        }
开发者ID:ubberkid,项目名称:PeerATT,代码行数:39,代码来源:OcspStatusRequest.cs

示例5: Main

        static void Main(string[] args)
        {
            MemoryStream m = new MemoryStream(64);
            Console.WriteLine("Lenth: {0}\tPosition: {1}\tCapacity: {2}",
                m.Length, m.Position, m.Capacity);

            for (int i = 0; i < 64; i++)
            {
                m.WriteByte((byte)i);
            }

            string s = "Foo";
            for (int i = 0; i < 3; i++)
            {
                m.WriteByte((byte)s[i]);
            }

            Console.WriteLine("Length: {0}\tPosition: {1}\tCapacity: {2}",
                m.Length, m.Position, m.Capacity);

            Console.WriteLine("\nContents:");
            byte[] ba = m.GetBuffer();

            foreach (byte b in ba)
            {
                Console.Write("{0,-3}", b);
            }

            FileStream fs = new FileStream("Goo.txt", FileMode.Create, FileAccess.Write);
            m.WriteTo(fs);
            fs.Close();
            m.Close();

            Console.ReadLine();
        }
开发者ID:GGammu,项目名称:InsideCSharp,代码行数:35,代码来源:Program.cs

示例6: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            // Read the input from the query string
            _percentage = float.Parse(Request.QueryString[ImageServerConstants.Pct]);
            _high = float.Parse(Request.QueryString[ImageServerConstants.High]);
            _low = float.Parse(Request.QueryString[ImageServerConstants.Low]);


            // set the ContentType appropriately, we are creating PNG image
            Response.ContentType = ImageServerConstants.ImagePng;

            // Load the background image
            Image bmp = Image.FromFile(Server.MapPath(ImageServerConstants.ImageURLs.UsageBar));
            Graphics graphics = Graphics.FromImage(bmp);
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            _width = bmp.Width;
            _height = bmp.Height;

            DrawUsageOverlay(ref graphics);

            // Save the image to memory stream (needed to do this if we are creating PNG image)
            MemoryStream MemStream = new MemoryStream();
            bmp.Save(MemStream, ImageFormat.Png);
            MemStream.WriteTo(Response.OutputStream);

            graphics.Dispose();
            bmp.Dispose();
        }
开发者ID:nhannd,项目名称:Xian,代码行数:29,代码来源:BarChart.aspx.cs

示例7: putPlugin

 public static void putPlugin(MemoryStream memStream, string pluginPath)
 {
     using (FileStream filePlugin = System.IO.File.Create(pluginPath))
     {
         memStream.WriteTo(filePlugin);
     }
 }
开发者ID:csongfr,项目名称:OGP,代码行数:7,代码来源:File_DAL.cs

示例8: Decompress

        /// <summary>
        /// Attempts to decompress the given input by letting all contained formats
        /// try to decompress the input.
        /// </summary>
        public override long Decompress(System.IO.Stream instream, long inLength, System.IO.Stream outstream)
        {
            byte[] inputData = new byte[instream.Length];
            instream.Read(inputData, 0, inputData.Length);

            foreach (CompressionFormat format in this.formats)
            {
                if (!format.SupportsDecompression)
                    continue;
                using (MemoryStream input = new MemoryStream(inputData))
                {
                    if (!format.Supports(input, inputData.Length))
                        continue;
                    MemoryStream output = new MemoryStream();
                    try
                    {
                        long decLength = format.Decompress(input, inputData.Length, output);
                        if (decLength > 0)
                        {
                            output.WriteTo(outstream);
                            return decLength;
                        }
                    }
                    catch (Exception) { continue; }
                }
            }

            throw new InvalidDataException("Input cannot be decompressed using the " + this.ShortFormatString + " formats.");
        }
开发者ID:dr1s,项目名称:rom_tool,代码行数:33,代码来源:CompositeFormat.cs

示例9: GetBytes

        public byte[] GetBytes()
        {
            byte[] bytes;
             using (MemoryStream ms = new MemoryStream())
             {
            TextHelper.StreamString(ms, Name);
            TextHelper.StreamString(ms, Location);
            TextHelper.StreamString(ms, Description);

            Int32 length;
            using (MemoryStream sensorsStream = new MemoryStream())
            {
               MessageHelper.SerializeSensorDescriptionsDataTimes(sensorsStream, Sensors);
               length = (int)sensorsStream.Length;
               ms.Write(BitConverter.GetBytes(length), 0, sizeof(Int32));
               sensorsStream.WriteTo(ms);
            }

            length = PictureBytes.Length;
            ms.Write(BitConverter.GetBytes(length), 0, sizeof(Int32));
            ms.Write(PictureBytes, 0, length);
            bytes = ms.ToArray();
             }
             return bytes;
        }
开发者ID:MarkPaxton,项目名称:SensorShare3,代码行数:25,代码来源:DescriptionMessage.cs

示例10: CreateFile

 public string CreateFile(string folder , string FileName , byte[] fs)
 {
     string path = DefaultValue.DEFAULT_ALBUM_ROOT_FILEPATH + folder;
     if (!Directory.Exists(path))
     {
         Directory.CreateDirectory(path);
     }
        try{
         ///���岢ʵ����һ���ڴ������Դ���ύ�������ֽ����顣
         MemoryStream m = new MemoryStream(fs);
         ///����ʵ���ļ����󣬱������ص��ļ���
         FileStream f = new FileStream( path + FileName, FileMode.Create);
         ///�����ڴ��������д�������ļ�
         m.WriteTo(f);
         m.Close();
         f.Close();
         f = null;
         m = null;
         return folder + FileName;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
开发者ID:KylinSky,项目名称:PowerSNS,代码行数:25,代码来源:PhotoFileAccess.cs

示例11: Main

		public static void Main(string[] args)
		{
			// Notes:
			// 1. All referenced assemblies shall
			//    define [assembly:Obfuscation(feature = "script")]
			// 2. Turn off "optimize code" option in release build
			// 3. All used .net APIs must be defined by ScriptCoreLibJava
			// 4. Generics are not supported.
			// 5. Check post build event
			// 6. Build in releas build configuration for java version

			Console.WriteLine("This console application can run at .net and java virtual machine!");

			var port = 18080;

			Console.WriteLine("http://127.0.0.1:" + port);


			port.ToListener(
				s =>
				{
					var request = new byte[0x1000];
					var requestc = s.Read(request, 0, request.Length);

					// StreamReader would be nice huh
					// ScriptCoreLibJava does not have it yet

					Console.WriteLine("client request " + requestc);

					// if we get the file name wrong we get a bad error message to stdout
					var data = File.ReadAllBytes("HTMLPage1.htm");
					Console.WriteLine("data length " + data.Length);

					var m = new MemoryStream();

					m.WriteLineASCII("HTTP/1.1 200 OK");
					m.WriteLineASCII("Content-Type:	text/html; charset=utf-8");
					m.WriteLineASCII("Content-Length: " + data.Length);
					m.WriteLineASCII("Connection: close");


					m.WriteLineASCII("");
					m.WriteLineASCII("");
					Console.WriteLine("headers written");

					m.WriteBytes(data);
					Console.WriteLine("data written");

					var Text = Encoding.ASCII.GetString(m.ToArray());
					m.WriteTo(s);
					Console.WriteLine("flush");

					s.Flush();
					s.Close();
				}
			);

			Console.WriteLine("press enter to exit!");
			Console.ReadLine();
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:60,代码来源:Program.cs

示例12: EmptyZip_AddEntry_SaveAndReRead_ShouldHaveSameContent

        public void EmptyZip_AddEntry_SaveAndReRead_ShouldHaveSameContent()
        {
            var data = new byte[] { 1, 2, 3, 4 };

            using (var stream = new MemoryStream())
            {
                using (var zip = new ZipFile())
                {
                    zip.AddEntry(STR_TestBin, data);
                    zip.Save(stream);

                    stream.Position = 0;
                    using (var fs = new FileStream(@"C:\Users\Ivan.z\Documents\test.bin.zip", FileMode.OpenOrCreate))
                    {
                        fs.Position = 0;

                        stream.WriteTo(fs);
                    }
                }

                stream.Position = 0;

                using (var zip = ZipFile.Read(stream))
                {
                    using (var ms = new MemoryStream())
                    {
                        zip[STR_TestBin].Extract(ms);

                        var actual = ms.ToArray();

                        CollectionAssert.AreEquivalent(data, actual);
                    }
                }
            }
        }
开发者ID:RainsSoft,项目名称:MarkerMetro.Unity.Pathfinding.Ionic.Zip,代码行数:35,代码来源:ZipFileTests.cs

示例13: Invoke

        public async Task Invoke(HttpContext context)
        {
            var memoryStream = new MemoryStream();
            var bodyStream = context.Response.Body;
            context.Response.Body = memoryStream;
            await _next?.Invoke(context);
            var request = context.Request;
            var response = context.Response;

            if(!string.IsNullOrWhiteSpace(request.Headers["X-XHR-Referer"]))
            {
                context.Response.Cookies.Append("request_method", request.Method, new CookieOptions { HttpOnly = false });
                if(context.Response.StatusCode == 301 || context.Response.StatusCode == 302)
                {
                    var uri = new Uri(response.Headers["Location"]);
                    if(uri.Host.Equals(request.Host.Value))
                    {
                        response.Headers["X-XHR-Redirected-To"] = response.Headers["Location"];
                    }
                }
            }
            memoryStream.WriteTo(bodyStream);
            await bodyStream.FlushAsync();
            memoryStream.Dispose();
            bodyStream.Dispose();
        }
开发者ID:TerribleDev,项目名称:TurboLinks.Net,代码行数:26,代码来源:TurboLinks.cs

示例14: Descargar

        public static void Descargar(HttpContext context,  string nombreArchivo, string contentType,string contenido = null, byte[] contenidoBytes=null)
        {
            context.Response.Clear();
            context.Response.ClearHeaders();
            context.Response.ClearContent();
            
            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", nombreArchivo));
            // set content type
            context.Response.ContentType = contentType;

            if (!string.IsNullOrWhiteSpace(contenido))
            {
                // add headers
                context.Response.AddHeader("Content-Length", contenido.Length.ToString(CultureInfo.InvariantCulture));
                // do AppendLine binary data to responce stream
                context.Response.Write(contenido);
            }

            if (contenidoBytes != null)
            {
                // add headers
                context.Response.AddHeader("Content-Length", contenidoBytes.Length.ToString(CultureInfo.InvariantCulture));
                MemoryStream ms = new MemoryStream(contenidoBytes);
                context.Response.Buffer = true;
                ms.WriteTo(context.Response.OutputStream);
            }

            // finish process
            context.Response.Flush();
            context.Response.SuppressContent = true;
            context.ApplicationInstance.CompleteRequest();
        }
开发者ID:berczeck,项目名称:.Net,代码行数:32,代码来源:HttpContextExtension.cs

示例15: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string fName = ConfigurationManager.AppSettings["Code39Barcode.FontFamily"];

        PrivateFontCollection fCollection = new PrivateFontCollection();
        fCollection.AddFontFile(ConfigurationManager.AppSettings["Code39Barcode.FontFile"]);
        FontFamily fFamily = new FontFamily(fName, fCollection);
        Font f = new Font(fFamily, FontSize);

        Bitmap bmp = new Bitmap(Width, Height);
        Graphics g = Graphics.FromImage(bmp);
        g.Clear(Color.White);
        Brush b = new SolidBrush(Color.Black);
        g.DrawString("*" + strPortfolioID + "*", f, b, 0, 0);

        //PNG format has no visible compression artifacts like JPEG or GIF, so use this format, but it needs you to copy the bitmap into a new bitmap inorder to display the image properly.  Weird MS bug.
        Bitmap bm = new Bitmap(bmp);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();

        Response.ContentType = "image/png";
        bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        ms.WriteTo(Response.OutputStream);

        b.Dispose();
        bm.Dispose();
        Response.End();
    }
开发者ID:nehawadhwa,项目名称:ccweb,代码行数:27,代码来源:CP_Barcode.ascx.cs


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