From 6a3752feb8f13541603e85326db997147047b2a6 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 6 Jul 2009 08:55:52 +0000 Subject: [PATCH] LUCENE-1734: CharReader should delegate reset/mark/markSupported git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@791415 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/analysis/CharFilter.java | 12 ++++++++++++ .../org/apache/lucene/analysis/CharReader.java | 12 ++++++++++++ .../lucene/analysis/MappingCharFilter.java | 12 ------------ .../lucene/analysis/TestMappingCharFilter.java | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) 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 );