本文整理汇总了C#中System.IO.MemoryStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.Flush方法的具体用法?C# System.IO.MemoryStream.Flush怎么用?C# System.IO.MemoryStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了System.IO.MemoryStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExtractArchiveTarGzCreateContainer
public void TestExtractArchiveTarGzCreateContainer()
{
CloudFilesProvider provider = (CloudFilesProvider)Bootstrapper.CreateObjectStorageProvider();
string containerName = TestContainerPrefix + Path.GetRandomFileName();
string sourceFileName = "DarkKnightRises.jpg";
byte[] content = File.ReadAllBytes("DarkKnightRises.jpg");
using (MemoryStream outputStream = new MemoryStream())
{
using (GZipOutputStream gzoStream = new GZipOutputStream(outputStream))
{
gzoStream.IsStreamOwner = false;
gzoStream.SetLevel(9);
using (TarOutputStream tarOutputStream = new TarOutputStream(gzoStream))
{
tarOutputStream.IsStreamOwner = false;
TarEntry entry = TarEntry.CreateTarEntry(containerName + '/' + sourceFileName);
entry.Size = content.Length;
tarOutputStream.PutNextEntry(entry);
tarOutputStream.Write(content, 0, content.Length);
tarOutputStream.CloseEntry();
tarOutputStream.Close();
}
}
outputStream.Flush();
outputStream.Position = 0;
ExtractArchiveResponse response = provider.ExtractArchive(outputStream, "", ArchiveFormat.TarGz);
Assert.IsNotNull(response);
Assert.AreEqual(1, response.CreatedFiles);
Assert.IsNotNull(response.Errors);
Assert.AreEqual(0, response.Errors.Count);
}
using (MemoryStream downloadStream = new MemoryStream())
{
provider.GetObject(containerName, sourceFileName, downloadStream, verifyEtag: true);
Assert.AreEqual(content.Length, GetContainerObjectSize(provider, containerName, sourceFileName));
downloadStream.Position = 0;
byte[] actualData = new byte[downloadStream.Length];
downloadStream.Read(actualData, 0, actualData.Length);
Assert.AreEqual(content.Length, actualData.Length);
using (MD5 md5 = MD5.Create())
{
byte[] contentMd5 = md5.ComputeHash(content);
byte[] actualMd5 = md5.ComputeHash(actualData);
Assert.AreEqual(BitConverter.ToString(contentMd5), BitConverter.ToString(actualMd5));
}
}
/* Cleanup
*/
provider.DeleteContainer(containerName, deleteObjects: true);
}
示例2: CloseAndFlush
public void CloseAndFlush()
{
var memStream = new System.IO.MemoryStream();
memStream.Close();
memStream.Flush();
}
示例3: OtherWaysToGetReport
private static void OtherWaysToGetReport()
{
string report = @"d:\bla.rdl";
// string lalal = System.IO.File.ReadAllText(report);
// byte[] foo = System.Text.Encoding.UTF8.GetBytes(lalal);
// byte[] foo = System.IO.File.ReadAllBytes(report);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
using (System.IO.FileStream file = new System.IO.FileStream(report, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
ms.Flush();
ms.Position = 0;
}
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("resource"))
{
using (System.IO.TextReader reader = new System.IO.StreamReader(ms))
{
// rv.LocalReport.LoadReportDefinition(reader);
}
}
using (System.IO.TextReader reader = System.IO.File.OpenText(report))
{
// rv.LocalReport.LoadReportDefinition(reader);
}
}
}
示例4: BinWriteDataSetToStream
private static void BinWriteDataSetToStream(System.IO.Stream stream, System.Data.DataSet ds)
{
//Version
IO.StreamPersistence.Write(stream, c_BinaryVersion);
//Schema byte[]
byte[] bytesSchema;
using (System.IO.MemoryStream schemaStream = new System.IO.MemoryStream())
{
ds.WriteXmlSchema(schemaStream);
schemaStream.Flush();
schemaStream.Seek(0, System.IO.SeekOrigin.Begin);
bytesSchema = schemaStream.ToArray();
}
IO.StreamPersistence.Write(stream, bytesSchema);
//Tables
for (int iTable = 0; iTable < ds.Tables.Count; iTable++)
{
System.Data.DataTable table = ds.Tables[iTable];
//Only the current Rows
System.Data.DataRow[] rows = table.Select(null, null, System.Data.DataViewRowState.CurrentRows);
IO.StreamPersistence.Write(stream, rows.Length);
//Rows
for (int r = 0; r < rows.Length; r++)
{
//Columns
for (int c = 0; c < table.Columns.Count; c++)
BinWriteFieldToStream(stream, rows[r][c], table.Columns[c].DataType);
}
}
}
示例5: Post
// POST api/values
public void Post([FromBody]string value)
{
var s = new System.IO.MemoryStream();
Request.Content.CopyToAsync(s);
s.Flush();
Console.WriteLine("payload:[{0}]", System.Text.Encoding.UTF8.GetString(s.ToArray()));
Console.WriteLine(value);
}
示例6: DeSerialize
public static SerializedObject DeSerialize(string messageBody)
{
byte[] bytes = Convert.FromBase64String(messageBody);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
stream.Write(bytes, 0, bytes.Length);
stream.Flush();
stream.Position = 0;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
object result = f.Deserialize(stream);
return (SerializedObject)result;
}
示例7: Post
//// GET: api/Values
//public IEnumerable<string> Get()
//{
// return new string[] { "value1", "value2" };
//}
//// GET: api/Values/5
//public string Get(int id)
//{
// return "value";
//}
// POST: api/Values
public string Post([FromBody]string value)
{
var enc = System.Text.Encoding.UTF8;
using (var mem = new System.IO.MemoryStream())
using (var gzip = new System.IO.Compression.GZipStream(mem, System.IO.Compression.CompressionMode.Compress, true))
using (var text = new System.IO.StreamWriter(gzip, enc, 0, true))
{
text.Write(value);
text.Flush();
mem.Flush();
mem.Seek(0, System.IO.SeekOrigin.Begin);
return System.Convert.ToBase64String(mem.ToArray());
}
}
示例8: WriteToStream
public System.IO.Stream WriteToStream(IPolicySetCache set, bool runtime)
{
using (System.IO.MemoryStream outputMemoryStream = new System.IO.MemoryStream())
{
using (ZipOutputStream zipOutputStream = new ZipOutputStream(outputMemoryStream))
{
WriteToZipStream(zipOutputStream, set, runtime);
System.IO.Stream returnStream = new System.IO.MemoryStream();
Crypto.Instance.WriteStreamToEncryptedStream(outputMemoryStream, returnStream, false);
returnStream.Flush();
returnStream.Position = 0;
return returnStream;
}
}
}
示例9: CopySelectedObjectsToClipboard
public void CopySelectedObjectsToClipboard()
{
System.Windows.Forms.DataObject dao = new System.Windows.Forms.DataObject();
ArrayList objectList = new ArrayList();
foreach (IHitTestObject o in this.m_SelectedObjects)
{
if (o.HittedObject is System.Runtime.Serialization.ISerializable)
{
objectList.Add(o.HittedObject);
}
}
dao.SetData("Altaxo.Graph.GraphObjectList", objectList);
// Test code to test if the object list can be serialized
#if false
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binform = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream stream = new System.IO.MemoryStream();
binform.Serialize(stream, objectList);
stream.Flush();
stream.Seek(0, System.IO.SeekOrigin.Begin);
object obj = binform.Deserialize(stream);
stream.Close();
stream.Dispose();
}
#endif
// now copy the data object to the clipboard
System.Windows.Forms.Clipboard.SetDataObject(dao, true);
}
示例10: DeSerialize
internal static object DeSerialize(byte[] obj)
{
if (obj == null || obj.Length<=0)
{
throw new ArgumentException("Parameter is invalid.", "obj", null);
}
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(obj))
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
ms.Seek(0, System.IO.SeekOrigin.Begin);
object result = bf.Deserialize(ms);
ms.Flush();
return result;
}
}
示例11: ExportarDinamicaButton1_Click
protected void ExportarDinamicaButton1_Click(object sender, EventArgs e)
{
System.Collections.Generic.List<CedForecastWebEntidades.Forecast> lista;
CedForecastWebEntidades.Forecast Forecast = new CedForecastWebEntidades.Forecast();
Forecast.IdTipoPlanilla = "RollingForecast";
Forecast.IdCuenta = CuentaDropDownList.SelectedValue.Trim();
CedForecastWebEntidades.Cliente cliente = new CedForecastWebEntidades.Cliente();
cliente.Id = ClienteDropDownList.SelectedValue.ToString().Trim();
Forecast.Cliente = cliente;
CedForecastWebRN.Periodo.ValidarPeriodoYYYYMM(PeriodoTextBox.Text);
Forecast.IdPeriodo = PeriodoTextBox.Text;
lista = CedForecastWebRN.Forecast.Lista(Forecast, (CedForecastWebEntidades.Sesion)Session["Sesion"]);
string archivo = "Id.Cliente; Nombre Cliente; Familia Artículo; Id.Artículo; Nombre Artículo; Periodo; Volumen";
archivo += "\r\n";
FileHelperEngine fhe = new FileHelperEngine(typeof(CedForecastWebEntidades.Forecast));
archivo += fhe.WriteString(lista);
byte[] a = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(archivo);
System.IO.MemoryStream m = new System.IO.MemoryStream(a);
Byte[] byteArray = m.ToArray();
m.Flush();
m.Close();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=RollingForecastDinamico.csv");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(byteArray);
Response.End();
}
示例12: TestExtractArchiveTarBz2
public void TestExtractArchiveTarBz2()
{
CloudFilesProvider provider = (CloudFilesProvider)Bootstrapper.CreateObjectStorageProvider();
string containerName = TestContainerPrefix + Path.GetRandomFileName();
string sourceFileName = "DarkKnightRises.jpg";
byte[] content = File.ReadAllBytes("DarkKnightRises.jpg");
using (MemoryStream outputStream = new MemoryStream())
{
using (BZip2OutputStream bz2Stream = new BZip2OutputStream(outputStream))
{
bz2Stream.IsStreamOwner = false;
using (TarArchive archive = TarArchive.CreateOutputTarArchive(bz2Stream))
{
archive.IsStreamOwner = false;
archive.RootPath = Path.GetDirectoryName(Path.GetFullPath(sourceFileName)).Replace('\\', '/');
TarEntry entry = TarEntry.CreateEntryFromFile(sourceFileName);
archive.WriteEntry(entry, true);
archive.Close();
}
}
outputStream.Flush();
outputStream.Position = 0;
ExtractArchiveResponse response = provider.ExtractArchive(outputStream, containerName, ArchiveFormat.TarBz2);
Assert.IsNotNull(response);
Assert.AreEqual(1, response.CreatedFiles);
Assert.IsNotNull(response.Errors);
Assert.AreEqual(0, response.Errors.Count);
}
using (MemoryStream downloadStream = new MemoryStream())
{
provider.GetObject(containerName, sourceFileName, downloadStream, verifyEtag: true);
Assert.AreEqual(content.Length, GetContainerObjectSize(provider, containerName, sourceFileName));
downloadStream.Position = 0;
byte[] actualData = new byte[downloadStream.Length];
downloadStream.Read(actualData, 0, actualData.Length);
Assert.AreEqual(content.Length, actualData.Length);
using (MD5 md5 = MD5.Create())
{
byte[] contentMd5 = md5.ComputeHash(content);
byte[] actualMd5 = md5.ComputeHash(actualData);
Assert.AreEqual(BitConverter.ToString(contentMd5), BitConverter.ToString(actualMd5));
}
}
/* Cleanup
*/
provider.DeleteContainer(containerName, deleteObjects: true);
}
示例13: Attach
public static bool Attach(bool noAutoExit)
{
lock (_syncRoot) {
NativeMethods.FileSafeHandle handle = null;
bool isFirstInstance = false;
try {
_mtxFirstInstance = new Mutex(true, MutexName, out isFirstInstance);
if (isFirstInstance == false) { //we need to contact previous instance.
_mtxFirstInstance = null;
byte[] buffer;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf.Serialize(ms, new NewInstanceEventArgs(System.Environment.CommandLine, System.Environment.GetCommandLineArgs()));
ms.Flush();
buffer = ms.GetBuffer();
}
//open pipe
if (!NativeMethods.WaitNamedPipe(NamedPipeName, NativeMethods.NMPWAIT_USE_DEFAULT_WAIT)) { throw new System.InvalidOperationException(Resources.ExceptionWaitNamedPipeFailed); }
handle = NativeMethods.CreateFile(NamedPipeName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, 0, System.IntPtr.Zero, NativeMethods.OPEN_EXISTING, NativeMethods.FILE_ATTRIBUTE_NORMAL, System.IntPtr.Zero);
if (handle.IsInvalid) {
throw new System.InvalidOperationException(Resources.ExceptionCreateFileFailed);
}
//send bytes
uint written = 0;
NativeOverlapped overlapped = new NativeOverlapped();
if (!NativeMethods.WriteFile(handle, buffer, (uint)buffer.Length, ref written, ref overlapped)) {
throw new System.InvalidOperationException(Resources.ExceptionWriteFileFailed);
}
if (written != buffer.Length) { throw new System.InvalidOperationException(Resources.ExceptionWriteFileWroteUnexpectedNumberOfBytes); }
} else { //there is no application already running.
_thread = new Thread(Run);
_thread.Name = "Medo.Application.SingleInstance.0";
_thread.IsBackground = true;
_thread.Start();
}
} catch (System.Exception ex) {
System.Diagnostics.Trace.TraceWarning(ex.Message + " {Medo.Application.SingleInstance}");
} finally {
//if (handle != null && (!(handle.IsClosed || handle.IsInvalid))) {
// handle.Close();
//}
if (handle != null) {
handle.Dispose();
}
}
if ((isFirstInstance == false) && (noAutoExit == false)) {
System.Diagnostics.Trace.TraceInformation("Exit(E_ABORT): Another instance is running. {Medo.Application.SingleInstance}");
System.Environment.Exit(unchecked((int)0x80004004)); //E_ABORT(0x80004004)
}
return isFirstInstance;
}
}
示例14: mnuProcess_Mail_Click
private void mnuProcess_Mail_Click(object sender, EventArgs e)
{
string sBody =
"Hello Yolanda Xie,\r\n" +
"\r\n" +
"Thank you for purchasing Naurtech software. Here are the registration keys for your software licenses. Please note that both the License ID and Registration keys are case sensitive. You can find instructions to manually register your license at:\r\n" +
"http://www.naurtech.com/wiki/wiki.php?n=Main.TrainingVideoManualRegistration\r\n" +
"\r\n" +
" Order Number: 15109\r\n" +
" Order Date: 4/10/2014\r\n" +
" Your PO Number: PO93504\r\n" +
" End Customer: Honeywell\r\n" +
" Product: [NAU-1504] CETerm for Windows CE 6.0 / 5.0 / CE .NET\r\n" +
" Quantity: 46\r\n" +
"\r\n" +
" Qty Ordered...............: 46\r\n" +
" Qty Shipped To Date.......: 46\r\n" +
"\r\n" +
" Qty Shipped in this email.: 46\r\n" +
"\r\n" +
"\r\n" +
"**** Registration Keys for Version 5.7 ***** \r\n" +
"\r\n" +
"\r\n" +
"Version 5.1 and above support AUTOMATED LICENSE REGISTRATION. Please use the attached license file. This prevents you from having to type each key to register your copy of the software. Please refer to support wiki article http://www.naurtech.com/wiki/wiki.php?n=Main.AutoRegistration\r\n" +
"";
string testFile = utils.helpers.getAppPath() + "LicenseXMLFileSample.xml";
System.IO.MemoryStream ms = new System.IO.MemoryStream();
//read file into memorystream
using (System.IO.FileStream file = new System.IO.FileStream(testFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
ms.Flush();
}
Attachement[] atts = new Attachement[] { new Attachement(ms, "test.xml") };
MailMessage msg = new MailMessage("E841719", sBody, "License Keys - Order: 15476: [NAU-1504] CETerm for Windows CE 6.0 / 5.0 / CE .NET", atts, DateTime.Now);
this.Cursor = Cursors.WaitCursor;
this.Enabled = false;
Application.DoEvents();
int i = _licenseMail.processMail(msg);
this.Enabled = true;
this.Cursor = Cursors.Default;
Application.DoEvents();
//setLblStatus("Updated data. Use refresh";
doRefresh();
}
示例15: loadXml
private bool loadXml(string filename)
{
if (!System.IO.File.Exists(filename))
{
MessageBox.Show(filename + " does not exist, please select a file");
return false;
}
string xmlstr = System.IO.File.ReadAllText(filename);
// Encode in UTF-8 byte array
byte[] encodedString = Encoding.UTF8.GetBytes(xmlstr);
// Put the byte array into a stream and rewind
System.IO.MemoryStream ms = new System.IO.MemoryStream(encodedString);
ms.Flush();
ms.Position = 0;
_xml.Load(ms);
return true;
}