// -----------------------------------------------------------------------
//
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// -----------------------------------------------------------------------
namespace Lucene.Net.Analysis
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
///
/// extends in order
/// to enforce an extra method . All tokenizers
/// accept a instead of for
/// this reason.
///
///
///
/// The enables arbitrary character based
/// filtering before tokenization.
///
///
/// The following methods, , ,
/// and were added to this abstract class as virtual methods
/// in case they were expected on all instances
/// due to Java's Reader implementation.
///
///
///
public abstract class CharStream : System.IO.StreamReader
{
///
/// Initializes a new instance of the class.
///
/// The reader.
protected CharStream(StreamReader reader)
: base(reader.BaseStream)
{
this.InnerReader = reader;
this.CurrentPosition = -1;
}
///
/// Gets or sets the current position.
///
/// The current position.
protected long CurrentPosition { get; set; }
///
/// Gets or sets the inner reader.
///
/// The inner reader.
protected StreamReader InnerReader { get; set; }
///
/// Corrects the offset.
///
///
///
/// fixes offsets to account for
/// removal or insertion of characters, so that the offsets
/// reported in the tokens match the character offsets of the
/// original Reader.
///
///
/// is generally invoked by Tokenizer classes
/// and CharFilter classes.
///
///
/// The offset for the output.
/// The offset based on the input.
public abstract int CorrectOffset(int offset);
///
/// Closes this instance.
///
public virtual void Close()
{
//// TODO: call close when the PLT finally supports it.
this.InnerReader.DiscardBufferedData();
}
///
/// Determines if the stream supports Marking/Seeking ahead.
///
///
/// An instance of .
public virtual bool MarkSupported()
{
return this.InnerReader.BaseStream.CanSeek;
}
///
/// Marks the seek position in the stream.
///
/// The limit of characters to read ahead.
public virtual void Mark(int readAheadLimit)
{
this.CurrentPosition = this.InnerReader.BaseStream.Position;
this.InnerReader.BaseStream.Position = readAheadLimit;
}
///
/// Resets the stream's position to the original position after
/// has been called.
///
public virtual void Reset()
{
this.InnerReader.BaseStream.Position = this.CurrentPosition;
}
}
}