本文整理汇总了C#中System.IO.TextReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.TextReader.Read方法的具体用法?C# System.IO.TextReader.Read怎么用?C# System.IO.TextReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了System.IO.TextReader.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFully
internal static int ReadFully(Reader reader, char[] dest, int offset, int len)
{
int read = 0;
while (read < len)
{
int r = reader.Read(dest, offset + read, len - read);
if (r == -1)
{
break;
}
read += r;
}
return read;
}
示例2: Load
/// <summary>
/// Loads and buffers the contents of the specified reader to be
/// used as this ANTLRReaderStream's source
/// </summary>
public virtual void Load(TextReader reader, int size, int readChunkSize)
{
if (reader == null)
{
return;
}
if (size <= 0)
{
size = INITIAL_BUFFER_SIZE;
}
if (readChunkSize <= 0)
{
readChunkSize = READ_BUFFER_SIZE;
}
try
{
// alloc initial buffer size.
data = new char[size];
// read all the data in chunks of readChunkSize
int numRead = 0;
int p = 0;
do
{
if (p + readChunkSize > data.Length)
{ // overflow?
char[] newdata = new char[data.Length * 2]; // resize
Array.Copy(data, 0, newdata, 0, data.Length);
data = newdata;
}
numRead = reader.Read(data, p, readChunkSize);
p += numRead;
} while (numRead != 0); // while not EOF
// set the actual size of the data available;
// EOF subtracted one above in p+=numRead; add one back
//n = p + 1;
n = p;
}
finally
{
reader.Close();
}
}