本文整理汇总了C#中OutputStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# OutputStream.Write方法的具体用法?C# OutputStream.Write怎么用?C# OutputStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputStream
的用法示例。
在下文中一共展示了OutputStream.Write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteMultipleData_OneFramePerWrite
public void WriteMultipleData_OneFramePerWrite()
{
using (Stream transport = new QueueStream())
using (WriteQueue queue = new WriteQueue(transport))
{
Task pumpTask = queue.PumpToStreamAsync();
Stream output = new OutputStream(1, Framing.Priority.Pri1, queue);
FrameReader reader = new FrameReader(transport, false, CancellationToken.None);
int dataLength = 100;
output.Write(new byte[dataLength], 0, dataLength);
output.Write(new byte[dataLength * 2], 0, dataLength * 2);
output.Write(new byte[dataLength * 3], 0, dataLength * 3);
Frame frame = reader.ReadFrameAsync().Result;
Assert.False(frame.IsControl);
Assert.Equal(dataLength, frame.FrameLength);
frame = reader.ReadFrameAsync().Result;
Assert.False(frame.IsControl);
Assert.Equal(dataLength * 2, frame.FrameLength);
frame = reader.ReadFrameAsync().Result;
Assert.False(frame.IsControl);
Assert.Equal(dataLength * 3, frame.FrameLength);
}
}
示例2: CopyStream
public static void CopyStream(Stream inputStream, OutputStream os)
{
int buffer_size = 1024;
try {
byte[] bytes = new byte[buffer_size];
for (;;) {
int count = inputStream.Read (bytes, 0, buffer_size);
if (count <= 0)
break;
os.Write (bytes, 0, count);
}
} catch (Exception ex) {
}
}
示例3: onSerialize
public override void onSerialize(OutputStream stream)
{
string json = JsonHelper.ToJson<MyOutput>(this);
byte[] data = Encoding.Default.GetBytes(json);
stream.Write(data, 0, data.Length);
stream.Flush();
}
示例4: 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;
}
示例5: _get
///tamir: updated to jcsh-0.1.30
private void _get(String src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip)
{
try
{
sendOPENR(src.GetBytes());
Header _header = new Header();
_header = header(buf, _header);
int length = _header.length;
int type = _header.type;
buf.rewind();
fill(buf.buffer, 0, length);
if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
{
throw new SftpException(SSH_FX_FAILURE, "Type is " + type);
}
if (type == SSH_FXP_STATUS)
{
int i = buf.getInt();
throwStatusError(buf, i);
}
byte[] handle = buf.getString(); // filename
long offset = 0;
if (mode == RESUME)
{
offset += skip;
}
int request_len = 0;
while (true)
{
request_len = buf.buffer.Length - 13;
if (server_version == 0)
{
request_len = 1024;
}
sendREAD(handle, offset, request_len);
_header = header(buf, _header);
length = _header.length;
type = _header.type;
int i;
if (type == SSH_FXP_STATUS)
{
buf.rewind();
fill(buf.buffer, 0, length);
i = buf.getInt();
if (i == SSH_FX_EOF)
{
goto BREAK;
}
throwStatusError(buf, i);
}
if (type != SSH_FXP_DATA)
{
goto BREAK;
}
buf.rewind();
fill(buf.buffer, 0, 4);
length -= 4;
i = buf.getInt(); // length of data
int foo = i;
while (foo > 0)
{
int bar = foo;
if (bar > buf.buffer.Length)
{
bar = buf.buffer.Length;
}
i = io.ins.read(buf.buffer, 0, bar);
if (i < 0)
{
goto BREAK;
}
int data_len = i;
dst.Write(buf.buffer, 0, data_len);
offset += data_len;
foo -= data_len;
if (monitor != null)
{
if (!monitor.count(data_len))
{
while (foo > 0)
{
i = io.ins.read(buf.buffer,
0,
(buf.buffer.Length < foo ? buf.buffer.Length : foo));
//.........这里部分代码省略.........