本文整理汇总了C#中System.IO.BufferedStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.Flush方法的具体用法?C# BufferedStream.Flush怎么用?C# BufferedStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
FileStream fs1 = new FileStream("out.bin",FileMode.Create,FileAccess.Write,FileShare.Read);
FileStream fs2 = new FileStream("out2.bin",FileMode.Create,FileAccess.Write,FileShare.Read);
bf1 = new BufferedStream(fs1);
bf2 = new BufferedStream(fs2);
try
{
Server server = new Server(10, 4096* 100 * 2);
server.Sequential = false;
server.Start(new IPEndPoint(IPAddress.Any, 40004));
server.MessageReceived += OnMessageReceived;
server.ClientConnected += OnClientConnected;
server.ClientDisconnected += OnClientDisconnected;
Console.ReadKey();
}
finally
{
bf1.Flush();
bf2.Flush();
bf1.Close();
bf2.Close();
fs1.Close();
fs2.Close();
}
}
示例2: Set
public void Set(string name, string key, RavenJObject data, UuidType uuidType)
{
Api.JetSetCurrentIndex(session, Lists, "by_name_and_key");
Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
Api.MakeKey(session, Lists, key, Encoding.Unicode, MakeKeyGrbit.None);
var exists = Api.TrySeek(session, Lists, SeekGrbit.SeekEQ);
using (var update = new Update(session, Lists, exists ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["name"], name, Encoding.Unicode);
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["key"], key, Encoding.Unicode);
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["etag"], uuidGenerator.CreateSequentialUuid(uuidType).TransformToValueForEsentSorting());
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["created_at"], SystemTime.UtcNow);
using (var columnStream = new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"]))
{
if (exists)
columnStream.SetLength(0);
using (Stream stream = new BufferedStream(columnStream))
{
data.WriteTo(stream);
stream.Flush();
}
}
update.Save();
}
}
示例3: Serialize
public byte[] Serialize(object o)
{
if (o == null)
{
throw new ArgumentNullException("o");
}
var type = o.GetType();
if (!type.IsDefined(typeof(SerializableAttribute), true))
{
throw new ArgumentException(
string.Format("The provided object cannot be serialized; [{0}] is not serializable", type));
}
using (var stream = new MemoryStream())
{
var buffer = new BufferedStream(stream);
var formatter = new BinaryFormatter();
formatter.Serialize(buffer, o);
buffer.Flush();
return stream.GetBuffer();
}
}
示例4: button3_Click
private void button3_Click(object sender, EventArgs e)
{
try
{
string str1 = textBox1.Text;
string str2 = textBox2.Text + "\\" + textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1, textBox1.Text.Length - textBox1.Text.LastIndexOf("\\") - 1);
Stream myStream1, myStream2;
BufferedStream myBStream1, myBStream2;
byte[] myByte = new byte[1024];
int i;
myStream1 = File.OpenRead(str1);
myStream2 = File.OpenWrite(str2);
myBStream1 = new BufferedStream(myStream1);
myBStream2 = new BufferedStream(myStream2);
i = myBStream1.Read(myByte, 0, 1024);
while (i > 0)
{
myBStream2.Write(myByte, 0, i);
i = myBStream1.Read(myByte, 0, 1024);
}
myBStream2.Flush();
myStream1.Close();
myBStream2.Close();
MessageBox.Show("文件复制完成");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例5: BadXmlTests
public void BadXmlTests()
{
try {
EncodeHelper.Deserialize("<garbage />", typeof(System.Object));
Assert.Fail("You should not have been able to deserialize this preceding xml");
}
catch {
}
MemoryStream ms = new MemoryStream();
using (StreamWriter sw = new StreamWriter(ms)) {
sw.Write("<garbage />");
sw.Flush();
object test = EncodeHelper.Deserialize(ms);
Assert.AreEqual(null, test);
}
try {
//Test the Deserialize method that builds an error message.
ms = new MemoryStream();
using (BufferedStream sw = new BufferedStream(ms)) {
sw.Write(Encoding.UTF8.GetPreamble(), 0, 3);
byte[] msg = System.Text.Encoding.UTF8.GetBytes("<garbage>");
sw.Write(msg, 0, msg.Length);
sw.Flush();
ms.Position = 0;
object test = EncodeHelper.Deserialize(ms);
Assert.AreEqual(null, test);
}
}
catch (Exception ex) {
if (ex.Message.IndexOf("Couldn't parse XML") == -1)
Assert.Fail("We should have failed for a bad xml file.");
}
}
示例6: AddAttachment
public Etag AddAttachment(string key, Etag etag, Stream data, RavenJObject headers)
{
Api.JetSetCurrentIndex(session, Files, "by_name");
Api.MakeKey(session, Files, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
var isUpdate = Api.TrySeek(session, Files, SeekGrbit.SeekEQ);
if (isUpdate)
{
var existingEtag = Etag.Parse(Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["etag"]));
if (existingEtag != etag && etag != null)
{
throw new ConcurrencyException("PUT attempted on attachment '" + key +
"' using a non current etag")
{
ActualETag = existingEtag,
ExpectedETag = etag
};
}
}
else
{
if (data == null)
throw new InvalidOperationException("When adding new attachment, the attachment data must be specified");
if (Api.TryMoveFirst(session, Details))
Api.EscrowUpdate(session, Details, tableColumnsCache.DetailsColumns["attachment_count"], 1);
}
Etag newETag = uuidGenerator.CreateSequentialUuid(UuidType.Attachments);
using (var update = new Update(session, Files, isUpdate ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["name"], key, Encoding.Unicode);
if (data != null)
{
long written;
using (var columnStream = new ColumnStream(session, Files, tableColumnsCache.FilesColumns["data"]))
{
if (isUpdate)
columnStream.SetLength(0);
using (var stream = new BufferedStream(columnStream))
{
data.CopyTo(stream);
written = stream.Position;
stream.Flush();
}
}
if (written == 0) // empty attachment
{
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["data"], new byte[0]);
}
}
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["etag"], newETag.TransformToValueForEsentSorting());
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["metadata"], headers.ToString(Formatting.None), Encoding.Unicode);
update.Save();
}
logger.Debug("Adding attachment {0}", key);
return newETag;
}
示例7: GetObjectPartly
public static void GetObjectPartly()
{
const string localFilePath = "<your localFilePath>";
const string bucketName = "<your bucketName>";
const string fileKey = "<your fileKey>";
const string accessId = "<your access id>";
const string accessKey = "<your access key>";
_client = new OssClient(accessId, accessKey);
using (var fileStream = new FileStream(localFilePath, FileMode.OpenOrCreate))
{
var bufferedStream = new BufferedStream(fileStream);
var objectMetadata = _client.GetObjectMetadata(bucketName, fileKey);
var fileLength = objectMetadata.ContentLength;
const int partSize = 1024 * 1024 * 10;
var partCount = CalPartCount(fileLength, partSize);
for (var i = 0; i < partCount; i++)
{
var startPos = partSize * i;
var endPos = partSize * i + (partSize < (fileLength - startPos) ? partSize : (fileLength - startPos)) - 1;
Download(bufferedStream, startPos, endPos, localFilePath, bucketName, fileKey);
}
bufferedStream.Flush();
}
}
示例8: Authenticate
public override void Authenticate(NpgsqlConnector context, byte[] password)
{
NpgsqlPasswordPacket pwpck = new NpgsqlPasswordPacket(password);
BufferedStream stream = new BufferedStream(context.Stream);
pwpck.WriteToStream(stream);
stream.Flush();
}
示例9: Authenticate
public override void Authenticate(NpgsqlConnector context, string password)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Authenticate");
NpgsqlPasswordPacket pwpck = new NpgsqlPasswordPacket(password, context.BackendProtocolVersion);
BufferedStream stream = new BufferedStream(context.Stream);
pwpck.WriteToStream(stream);
stream.Flush();
}
示例10: Stream2Test
public void Stream2Test()
{
var ms = new BufferedStream(new MemoryStream());
Console.WriteLine(ms.CanWrite);
Console.WriteLine(ms.CanRead);
ms.Write(new byte[3] { 1, 2, 3 }, 0, 3);
ms.Flush();
var bys = new byte[10];
var len = ms.Read(bys, 0, 10);
Console.WriteLine(len + "->" + bys[0]);
}
示例11: Execute
public void Execute()
{
MemoryStream buffer = new MemoryStream();
formatter.Serialize(buffer, message);
byte[] bytes = buffer.ToArray();
byte[] size = BitConverter.GetBytes((int)buffer.Length);
Stream stream = new BufferedStream(client.GetStream());
stream.Write(size, 0, size.Length);
stream.Write(bytes, 0, bytes.Length);
stream.Flush();
}
示例12: Decompress
public static void Decompress(Stream instream, Stream outstream)
{
BufferedStream stream = new BufferedStream(outstream);
BufferedStream zStream = new BufferedStream(instream);
if ((zStream.ReadByte() == 0x42) && (zStream.ReadByte() == 90))
{
BZip2InputStream stream3 = new BZip2InputStream(zStream);
for (int i = stream3.ReadByte(); i != -1; i = stream3.ReadByte())
{
stream.WriteByte((byte) i);
}
stream.Flush();
}
}
示例13: Case1
/// <summary>
/// BufferedStream使用装饰模式
/// 继承Stream基类,提供同样的接口
/// 可以封装其他继承自Stream的类,提供缓存的功能
/// </summary>
static void Case1()
{
string filePath = @"test.txt";
if (File.Exists(filePath))
File.Delete(filePath);
using(FileStream fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
{
using (BufferedStream bs = new BufferedStream(fs))
{
Output(bs, "I am Simon.\r\n");
Output(bs, "How are you?");
bs.Flush();
}
}
}
示例14: Buffered_Stream_buffers_and_forwards_writes_and_flushes_before_close
public void Buffered_Stream_buffers_and_forwards_writes_and_flushes_before_close()
{
var mock = new Mock<Stream>();
Stream stream = mock.Object;
mock.SetupGet(d => d.CanRead).Returns(true);
mock.SetupGet(d => d.CanWrite).Returns(true);
BufferedStream bs = new BufferedStream(stream);
bs.WriteByte((byte)'a');
bs.Flush();
bs.Close();
mock.Verify(d => d.Write(It.Is<byte[]>(array => array.Length > 0 && array[0] == 'a'), 0, 1));
mock.Verify(d => d.Flush());
mock.Verify(d => d.Close());
}
示例15: CreateTestFile
/// <summary>
/// 테스트용 임시 파일을 생성한다.
/// </summary>
public FileInfo CreateTestFile(string filepath, long size) {
var fi = new FileInfo(filepath);
var buffer = new byte[BufferSize];
ArrayTool.GetRandomBytes(buffer);
using(var bs = new BufferedStream(fi.OpenWrite())) {
long writeCount = 0;
do {
bs.Write(buffer, 0, BufferSize);
writeCount += BufferSize;
} while(size > writeCount);
bs.Flush();
}
return fi;
}