本文整理汇总了C#中MemoryStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.Dispose方法的具体用法?C# MemoryStream.Dispose怎么用?C# MemoryStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompressResponse
/// <summary>
/// Compresses the response stream if the browser allows it.
/// </summary>
private static MemoryStream CompressResponse(Stream responseStream, HttpApplication app, string key)
{
MemoryStream dataStream = new MemoryStream();
StreamCopy(responseStream, dataStream);
responseStream.Dispose();
byte[] buffer = dataStream.ToArray();
dataStream.Dispose();
MemoryStream ms = new MemoryStream();
Stream compress = null;
if (IsEncodingAccepted(DEFLATE))
{
compress = new DeflateStream(ms, CompressionMode.Compress);
app.Application.Add(key + "enc", DEFLATE);
}
else if (IsEncodingAccepted(GZIP))
{
compress = new GZipStream(ms, CompressionMode.Compress);
app.Application.Add(key + "enc", DEFLATE);
}
compress.Write(buffer, 0, buffer.Length);
compress.Dispose();
return ms;
}
示例2: RunCommand
public CommandResult RunCommand(string command)
{
CommandResult result = new CommandResult();
MemoryStream ms = new MemoryStream();
try
{
m_pythonEngine.Runtime.IO.SetOutput(ms, new StreamWriter(ms, Encoding.UTF8));
object o = m_pythonEngine.Execute(command, m_scriptScope);
result.output = ReadStream(ms);
if (o != null)
{
result.returnValue = o;
m_scriptScope.SetVariable("_", o);
try
{
string objectStr = m_pythonEngine.Execute("repr(_)", m_scriptScope).ToString();
result.returnValueStr = objectStr;
}
catch
{
result.returnValueStr = o.ToString();
}
}
}
catch (System.Exception e)
{
result.output = ReadStream(ms);
result.exception = e;
}
ms.Dispose();
return result;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
String qs = Request.QueryString.Get("bid");
Response.Write("Query String = " + qs);
SqlConnection sql = new SqlConnection();
sql.ConnectionString = "Data Source=(local);Initial Catalog=Hotel;Integrated Security=True";
sql.Open();
ReportDocument rpd = new ReportDocument();
rpd.Load(Server.MapPath("itcreport.rpt"));
rpd.SetDatabaseLogon("sa", "ak");
rpd.SetParameterValue(0, qs);
CrystalReportViewer1.ReportSource = rpd;
//to convert report in pdf format
MemoryStream ostream = new MemoryStream();
Response.Clear();
Response.Buffer = true;
ostream = (MemoryStream)rpd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
rpd.Close();
rpd.Dispose();
Response.ContentType = "application/pdf";
Response.BinaryWrite(ostream.ToArray());
ostream.Flush();
ostream.Close();
ostream.Dispose();
}
示例4: BaseStream1
public void BaseStream1()
{
var writeStream = new MemoryStream();
var zip = new DeflateStream(writeStream, CompressionMode.Compress);
Assert.Same(zip.BaseStream, writeStream);
writeStream.Dispose();
}
示例5: BaseStream2
public void BaseStream2()
{
var ms = new MemoryStream();
var zip = new DeflateStream(ms, CompressionMode.Decompress);
Assert.Same(zip.BaseStream, ms);
ms.Dispose();
}
示例6: Decrypt
/// <summary>
/// ถอดรหัสข้อมูล
/// </summary>
/// <param name="Value">ข้อมูลที่ต้องการให้ถอดรหัส</param>
/// <returns>ข้อมูลหลังจากถอดรหัส</returns>
/// <example>
/// clsSecurity.Decrypt("e0NDKIlUhHF3qcIdkmGpZw==");
/// </example>
public string Decrypt(string Value)
{
#region Variable
SymmetricAlgorithm mCSP;
ICryptoTransform ct = null;
MemoryStream ms = null;
CryptoStream cs = null;
byte[] byt;
byte[] result;
#endregion
#region Procedure
mCSP = new RijndaelManaged();
try
{
mCSP.Key = _key;
mCSP.IV = _initVector;
ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV);
byt = Convert.FromBase64String(Value);
ms = new MemoryStream();
cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
cs.Write(byt, 0, byt.Length);
cs.FlushFinalBlock();
cs.Close();
result = ms.ToArray();
}
catch
{
result = null;
}
finally
{
if (ct != null)
ct.Dispose();
if (ms != null)
if (ms.CanRead)
{
ms.Dispose();
}
if (cs != null)
if (cs.CanRead)
{
cs.Dispose();
}
}
try
{
return ASCIIEncoding.UTF8.GetString(result);
}
catch (Exception)
{
return "";
}
#endregion
}
示例7: GetObjectSize
private static long GetObjectSize(object obj)
{
var bf = new BinaryFormatter();
var ms = new MemoryStream();
bf.Serialize(ms, obj);
var size = ms.Length;
ms.Dispose();
return size;
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetNoStore();
Response.ContentType = "application/xml";
DataTable dt = CreateBll.GetInfo(TABLE_NAME, 1, 100);
MemoryStream ms = new MemoryStream();
XmlTextWriter xmlTW = new XmlTextWriter(ms, Encoding.UTF8);
xmlTW.Formatting = Formatting.Indented;
xmlTW.WriteStartDocument();
xmlTW.WriteStartElement("urlset");
xmlTW.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
xmlTW.WriteAttributeString("xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9");
foreach (DataRow dr in dt.Rows)
{
xmlTW.WriteStartElement("url");
string infoUrl = CreateBll.GetInfoUrl(dr,1).ToLower();
if(!infoUrl.StartsWith("http://")&&!infoUrl.StartsWith("https://")&&!infoUrl.StartsWith("ftp://"))
{
if(Param.ApplicationRootPath==string.Empty)
{
infoUrl = CreateBll.SiteModel.Domain+infoUrl;
}
else
{
infoUrl = infoUrl.Replace(Param.ApplicationRootPath.ToLower(),string.Empty);
infoUrl = CreateBll.SiteModel.Domain+infoUrl;
}
}
xmlTW.WriteElementString("loc", infoUrl);
xmlTW.WriteStartElement("news:news");
xmlTW.WriteElementString("news:publication_date", dr["addtime"].ToString());
string keywords = dr["tagnamestr"].ToString();
if (keywords.StartsWith("|") && keywords.EndsWith("|"))
{
keywords = keywords.Substring(0, keywords.Length - 1);
keywords = keywords.Substring(1, keywords.Length - 1);
keywords = keywords.Replace("|",",");
}
xmlTW.WriteElementString("news:keywords", keywords);
xmlTW.WriteEndElement();
xmlTW.WriteEndElement();
}
xmlTW.WriteEndDocument();
xmlTW.Flush();
byte[] buffer = ms.ToArray();
Response.Write(Encoding.UTF8.GetString(buffer));
Response.End();
xmlTW.Close();
ms.Close();
ms.Dispose();
}
示例9: Start
protected override IEnumerator Start()
{
MemoryStream ms = new MemoryStream();
//=================================================
CSProto01 proto = new CSProto01();
proto.a = 12345;
proto.b = "协议1";
Debug.LogWarning("原数据:" + proto.desc);
ms.Position = 0;
CSLightMng.instance.Serialize(ms, proto);
ms.Position = 0;
CSProto01 proto2 = (CSProto01)CSLightMng.instance.Deserialize(ms, "CSProto01");
Debug.LogWarning("序列化和反序列化后:" + proto2.desc);
//=================================================
CSProto02 proto3 = new CSProto02();
proto3.a = proto;
proto3.b = "协议2";
Debug.LogWarning("原数据:" + proto3.desc);
ms.Position = 0;
CSLightMng.instance.Serialize(ms, proto3);
ms.Position = 0;
CSProto02 proto4 = (CSProto02)CSLightMng.instance.Deserialize(ms, "CSProto02");
Debug.LogWarning("序列化和反序列化后:" + proto4.desc);
//=================================================
CSProto03 proto5 = new CSProto03();
proto5.a = proto4;
proto5.b = "协议3";
proto5.c = new List<CSProto01>();
proto5.c.Add(proto);
proto5.c.Add(proto2);
Debug.LogWarning("原数据:" + proto5.desc);
ms.Position = 0;
CSLightMng.instance.Serialize(ms, proto5);
ms.Position = 0;
CSProto03 proto6 = (CSProto03)CSLightMng.instance.Deserialize(ms, "CSProto03");
Debug.LogWarning("序列化和反序列化后:" + proto6.desc);
ms.Dispose();
yield return 0;
}
示例10: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
response.Clear();
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = this.ContentType;
response.AppendHeader("content-disposition", "attachment; filename=deadfolder.pdf");
var stream = new MemoryStream(this.ContentBytes);
stream.WriteTo(response.OutputStream);
stream.Dispose();
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//Bitmap map;
if (Request["chartImg"] != null && Request["chartType"] != null && Request["tableData"] != null && Request["source"] != null && Request["keywords"] != null && Request["title"] != null && Request["subtitle"] != null && Request["filename"] != null)
{
string imageBitString = Request["chartImg"].ToString();
string imageType = Request["chartType"].ToString();
string tTableData = Request["tableData"].ToString();
string tSource = Request["source"].ToString();
string tKeywords = Request["keywords"].ToString();
string tTitle = Request["title"].ToString();
string tSubtitle = Request["subtitle"].ToString();
string tfilename = Request["filename"].ToString();
if (String.IsNullOrEmpty(tfilename))
tfilename = "radar";
string extenstion =string.Empty;
string contentType = string.Empty;
MemoryStream tData = null;
switch(imageType.ToLower())
{
case "image/png":
tData = new MemoryStream();
MemoryStream picStream = new MemoryStream(Convert.FromBase64String(imageBitString));
extenstion = ".png";
contentType = "image/png";
tData = picStream;
picStream.Close();
picStream.Dispose();
break;
case "application/vnd.xls":
tData = new MemoryStream();
Callback callbackObj = new Callback(this.Page);
IWorkbook workbook = callbackObj.getWorkbookForSwf(tTitle, tSubtitle, tSource, tKeywords, tTableData, imageBitString);
if (workbook!=null)
workbook.SaveToStream(tData, FileFormat.XLS97);
else
workbook.SaveToStream(tData, FileFormat.XLS97);
workbook.Close();
extenstion = ".xls";
contentType = "application/vnd.xls";
break;
}
tData.Close();
tData.Dispose();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = contentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + tfilename + extenstion +"");
Response.BinaryWrite(tData.ToArray());
Response.End();
}
}
示例12: SerializeToBytes
/// <summary>
/// 序列化对象到字节数组
/// </summary>
/// <param name="objectToSerialize">要序列化的对象</param>
/// <returns>返回创建后的字节数组</returns>
public static byte[] SerializeToBytes(this object objectToSerialize)
{
byte[] result = null;
if (objectToSerialize == null)
return result;
using (var ms = new MemoryStream())
{
objectToSerialize.SerializeToStream(ms);
ms.Dispose();
result = ms.ToArray();
}
return result;
}
示例13: SaveImage
public static void SaveImage(byte[] bytes,string path)
{
Bitmap imagen = (Bitmap)System.Drawing.Image.FromStream(new MemoryStream(bytes));
MemoryStream stream = new MemoryStream();
try
{
imagen.SetResolution(400, 300);
FileStream file = new FileStream(path, FileMode.OpenOrCreate);
imagen.Save(stream,ImageFormat.Jpeg);
stream.WriteTo(file);
file.Close();
}
finally
{
stream.Dispose();
}
//GC.ReRegisterForFinalize(imagen);
}
示例14: DecompressFileLZMA
public static byte[] DecompressFileLZMA(byte[] inBytes)
{
SevenZip.Compression.LZMA.Decoder coder = new SevenZip.Compression.LZMA.Decoder();
var input = new MemoryStream(inBytes);
var output = new MemoryStream();
byte[] ret = null;
try
{
// Read the decoder properties
byte[] properties = new byte[5];
input.Read(properties, 0, 5);
// Read in the decompress file size.
byte[] fileLengthBytes = new byte[8];
input.Read(fileLengthBytes, 0, 8);
long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
// Decompress the file.
coder.SetDecoderProperties(properties);
coder.Code(input, output, input.Length, fileLength, null);
output.Flush();
ret = output.GetBuffer();
}
catch
{
throw;
}
finally
{
output.Close();
output.Dispose();
input.Close();
input.Dispose();
}
return ret;
}
示例15: CompressFile
public static void CompressFile(string toCompressFileName,string targetFileName,bool IsDeleteSourceFile)
{
FileStream reader;
reader = File.Open(toCompressFileName, FileMode.Open);
FileStream writer;
writer = File.Create(targetFileName);
//压缩相关的流
MemoryStream ms = new MemoryStream();
GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress, true);
//往压缩流中写数据
byte[] sourceBuffer = new byte[reader.Length];
reader.Read(sourceBuffer, 0, sourceBuffer.Length);
zipStream.Write(sourceBuffer, 0, sourceBuffer.Length);
//一定要在内存流读取之前关闭压缩流
zipStream.Close();
zipStream.Dispose();
//从内存流中读数据
ms.Position = 0; //注意,不要遗漏此句
byte[] destBuffer = new byte[ms.Length];
ms.Read(destBuffer, 0, destBuffer.Length);
writer.Write(destBuffer, 0, destBuffer.Length);
//关闭并释放内存流
ms.Close();
ms.Dispose();
//关闭并释放文件流
writer.Close();
writer.Dispose();
reader.Close();
reader.Dispose();
if (IsDeleteSourceFile)
{
File.Delete(toCompressFileName);
}
}