diff --git a/src/java/org/apache/lucene/analysis/CharFilter.java b/src/java/org/apache/lucene/analysis/CharFilter.java index 20cf1d29f6a..f0012fdf7c7 100644 --- a/src/java/org/apache/lucene/analysis/CharFilter.java +++ b/src/java/org/apache/lucene/analysis/CharFilter.java @@ -58,4 +58,16 @@ public abstract class CharFilter extends CharStream { public int read(char[] cbuf, int off, int len) throws IOException { return input.read(cbuf, off, len); } + + public boolean markSupported(){ + return input.markSupported(); + } + + public void mark( int readAheadLimit ) throws IOException { + input.mark(readAheadLimit); + } + + public void reset() throws IOException { + input.reset(); + } } diff --git a/src/java/org/apache/lucene/analysis/CharReader.java b/src/java/org/apache/lucene/analysis/CharReader.java index 30c38612913..b05782755a2 100644 --- a/src/java/org/apache/lucene/analysis/CharReader.java +++ b/src/java/org/apache/lucene/analysis/CharReader.java @@ -50,4 +50,16 @@ public final class CharReader extends CharStream { public int read(char[] cbuf, int off, int len) throws IOException { return input.read(cbuf, off, len); } + + public boolean markSupported(){ + return input.markSupported(); + } + + public void mark( int readAheadLimit ) throws IOException { + input.mark(readAheadLimit); + } + + public void reset() throws IOException { + input.reset(); + } } diff --git a/src/java/org/apache/lucene/analysis/MappingCharFilter.java b/src/java/org/apache/lucene/analysis/MappingCharFilter.java index 7ec6a50972a..0c23f9376f6 100644 --- a/src/java/org/apache/lucene/analysis/MappingCharFilter.java +++ b/src/java/org/apache/lucene/analysis/MappingCharFilter.java @@ -125,16 +125,4 @@ public class MappingCharFilter extends BaseCharFilter { } return l == 0 ? -1 : l; } - - public boolean markSupported() { - return false; - } - - public void mark(int readAheadLimit) throws IOException { - throw new IOException("mark/reset not supported"); - } - - public void reset() throws IOException { - throw new IOException("mark/reset not supported"); - } } diff --git a/src/test/org/apache/lucene/analysis/TestMappingCharFilter.java b/src/test/org/apache/lucene/analysis/TestMappingCharFilter.java index 34d8eeb8684..520b67ccc46 100644 --- a/src/test/org/apache/lucene/analysis/TestMappingCharFilter.java +++ b/src/test/org/apache/lucene/analysis/TestMappingCharFilter.java @@ -40,6 +40,22 @@ public class TestMappingCharFilter extends BaseTokenTestCase { normMap.add( "empty", "" ); } + public void testReaderReset() throws Exception { + CharStream cs = new MappingCharFilter( normMap, CharReader.get( new StringReader( "x" ) ) ); + char[] buf = new char[10]; + int len = cs.read(buf, 0, 10); + assertEquals( 1, len ); + assertEquals( 'x', buf[0]) ; + len = cs.read(buf, 0, 10); + assertEquals( -1, len ); + + // rewind + cs.reset(); + len = cs.read(buf, 0, 10); + assertEquals( 1, len ); + assertEquals( 'x', buf[0]) ; + } + public void testNothingChange() throws Exception { CharStream cs = new MappingCharFilter( normMap, CharReader.get( new StringReader( "x" ) ) ); TokenStream ts = new WhitespaceTokenizer( cs );