本文整理汇总了C#中Reader.read方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.read方法的具体用法?C# Reader.read怎么用?C# Reader.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reader
的用法示例。
在下文中一共展示了Reader.read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToString
/// <summary>
/// Reads until end-of-stream and returns all read chars, finally closes the stream.
/// </summary>
/// <param name="input"> the input stream </param>
/// <exception cref="IOException"> if an I/O error occurs while reading the stream </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static String toString(java.io.Reader input) throws java.io.IOException
private static string ToString(Reader input)
{
if (input is FastStringReader) // fast path
{
return ((FastStringReader) input).String;
}
try
{
int len = 256;
char[] buffer = new char[len];
char[] output = new char[len];
len = 0;
int n;
while ((n = input.read(buffer)) >= 0)
{
if (len + n > output.Length) // grow capacity
{
char[] tmp = new char[Math.Max(output.Length << 1, len + n)];
Array.Copy(output, 0, tmp, 0, len);
Array.Copy(buffer, 0, tmp, len, n);
buffer = output; // use larger buffer for future larger bulk reads
output = tmp;
}
else
{
Array.Copy(buffer, 0, output, len, n);
}
len += n;
}
return new string(output, 0, len);
}
finally
{
input.close();
}
}
示例2: fillBuffer
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void fillBuffer(StringBuilder sb, java.io.Reader input) throws java.io.IOException
private void fillBuffer(StringBuilder sb, Reader input)
{
int len;
sb.Length = 0;
while ((len = input.read(buffer)) > 0)
{
sb.Append(buffer, 0, len);
}
}