本文整理汇总了C#中System.IO.TextReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.TextReader.Close方法的具体用法?C# System.IO.TextReader.Close怎么用?C# System.IO.TextReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了System.IO.TextReader.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public virtual void Load(TextReader r, int size, int readChunkSize) {
if (r == null) {
return;
}
if (size <= 0) {
size = InitialBufferSize;
}
if (readChunkSize <= 0) {
readChunkSize = ReadBufferSize;
}
// System.out.println("load "+size+" in chunks of "+readChunkSize);
try {
data = r.ReadToEnd().ToCharArray();
base.n = data.Length;
} finally {
r.Close();
}
}
示例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();
}
}
示例3: CloseConnection
protected virtual void CloseConnection()
{
try
{
@in.Close();
@in = null;
@out.Close();
@out = null;
channel.Close();
channel = null;
}
catch ( Exception e )
{
Console.Error.WriteLine( e );
e.PrintStackTrace( Console.Error );
}
finally
{
if ( @in != null )
{
try
{
@in.Close();
}
catch ( IOException ioe )
{
Console.Error.WriteLine( ioe );
}
}
if ( @out != null )
{
@out.Close();
}
if ( channel != null )
{
try
{
channel.Close();
}
catch ( IOException ioe )
{
Console.Error.WriteLine( ioe );
}
}
}
}