本文整理汇总了C#中IInputStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# IInputStream.Read方法的具体用法?C# IInputStream.Read怎么用?C# IInputStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInputStream
的用法示例。
在下文中一共展示了IInputStream.Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadStringFromInputStream
public bool ReadStringFromInputStream(IInputStream inputStream, List<string> messages, out string s)
{
var bytesCollection = new List<byte[]>();
var bytes = new byte[Environment.SystemPageSize];
while (true)
{
var bytesRead = inputStream.Read(bytes, _timeout);
if (bytesRead <= 0) break;
var bytesCopy = new byte[bytesRead];
Buffer.BlockCopy(bytes, 0, bytesCopy, 0, bytesRead);
bytesCollection.Add(bytesCopy);
}
var bytesCount = bytesCollection.Sum(bytesChunk => bytesChunk.Length);
bytes = new byte[bytesCount];
var offset = 0;
foreach (var bytesChunk in bytesCollection)
{
Buffer.BlockCopy(bytesChunk, 0, bytes, offset, bytesChunk.Length);
offset += bytesChunk.Length;
}
try
{
s = _encoding.GetString(bytes);
}
catch (Exception e)
{
messages.Add(e.ToString());
s = null;
return false;
}
return true;
}
示例2: Copy
/// <exception cref="System.IO.IOException"></exception>
protected virtual void Copy(IInputStream rawin, Socket4Adapter sock, bool update)
{
BufferedInputStream @in = new BufferedInputStream(rawin);
byte[] buffer = new byte[BlobImpl.CopybufferLength];
int bytesread = -1;
while ((bytesread = rawin.Read(buffer)) >= 0)
{
sock.Write(buffer, 0, bytesread);
if (update)
{
_currentByte += bytesread;
}
}
@in.Close();
}
示例3: Write
public void Write(
IInputStream data
)
{
// TODO:IMPL bufferize!!!
byte[] baseData = new byte[data.Length];
// Force the source pointer to the BOF (as we must copy the entire content)!
data.Position = 0;
// Read source content!
data.Read(baseData, 0, baseData.Length);
// Write target content!
Write(baseData);
}