本文整理汇总了C#中OutputStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# OutputStream.Close方法的具体用法?C# OutputStream.Close怎么用?C# OutputStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputStream
的用法示例。
在下文中一共展示了OutputStream.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalSendMessage
private Stream InternalSendMessage(Message message)
{
if(!IsAlive)
throw new RemotingException("TCP error: Connection closed!");
writer.Write(magic);
writer.Write(Version);
writer.Write((byte)message.Type);
writer.Write(ThisMachineID.ToByteArray());
writer.Write(message.ID.ToByteArray());
foreach(DictionaryEntry entry in message.Headers)
{
writer.Write((string)entry.Key);
writer.Write((string)entry.Value);
}
writer.Write("");
Stream outStream = new OutputStream(this);
if(message.Stream != null)
{
MemoryStream ms = message.Stream as MemoryStream;
if(ms != null)
try
{
outStream.Write(ms.GetBuffer(), 0, (int)ms.Length);
}
catch(UnauthorizedAccessException)
{
ms = null;
}
if(ms == null)
{
byte[] buffer = new byte[DefaultBufferSize];
while(true)
{
int read = message.Stream.Read(buffer, 0, buffer.Length);
if(read == 0)
break;
outStream.Write(buffer, 0, read);
}
}
outStream.Close();
return null;
}
return outStream;
}