本文整理汇总了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
{
}
}
示例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();
}
示例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
}
示例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);
}
}
示例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();
}
示例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();
}
示例7: putPlugin
public static void putPlugin(MemoryStream memStream, string pluginPath)
{
using (FileStream filePlugin = System.IO.File.Create(pluginPath))
{
memStream.WriteTo(filePlugin);
}
}
示例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.");
}
示例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;
}
示例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;
}
}
示例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();
}
示例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);
}
}
}
}
示例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();
}
示例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();
}
示例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();
}