BufferedTextReader.cs :  » GIS » NetTopologySuite » RTools_NTS » Util » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » NetTopologySuite 
NetTopologySuite » RTools_NTS » Util » BufferedTextReader.cs
// BufferedTextReader.cs
// 
// Copyright (C) 2003 Ryan Seghers
//
// This software is provided AS IS. No warranty is granted, 
// neither expressed nor implied. USE THIS SOFTWARE AT YOUR OWN RISK.
// NO REPRESENTATION OF MERCHANTABILITY or FITNESS FOR ANY 
// PURPOSE is given.
//
// License to use this software is limited by the following terms:
// 1) This code may be used in any program, including programs developed
//    for commercial purposes, provided that this notice is included verbatim.
//    
// Also, in return for using this code, please attempt to make your fixes and
// updates available in some way, such as by sending your updates to the
// author.

using System;
using System.IO;

namespace RTools_NTS.Util{
  /// <summary>
  /// Wraps a TextReader with buffering for speed. This is not finished,
  /// and preliminary testing indicates it isn't faster than FCL implementation.
  /// </summary>
  public class BufferedTextReader
  {
    static readonly int BlockSize = 1024;
    TextReader reader;
    char[] buffer;
    CharBuffer cb;

    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="reader">The TextReader to wrap.</param>
    public BufferedTextReader(TextReader reader)
    {
      this.reader = reader;
      buffer = new char[BlockSize];
      cb = new CharBuffer(0);
    }

    /// <summary>
    /// Read a single character.
    /// </summary>
    /// <returns>The character read.</returns>
    public char Read()
    {
      if (cb.Length == 0)
      {
        // read from underlying reader
        int readCount = reader.Read(buffer, 0, BlockSize);
        if (readCount == 0) throw new ApplicationException("End of stream.");
        cb.SetBuffer(buffer, readCount);
      }

      char c = cb[0]; 
      cb.Remove(0); 
      return(c);
    }

    /// <summary>
    /// Close the underlying reader.
    /// </summary>
    public void Close()
    {
      reader.Close();
      cb = null;
    }
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.