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
This commit is contained in:
Uwe Schindler 2009-07-06 08:55:52 +00:00
parent 7acabfecf0
commit 6a3752feb8
4 changed files with 40 additions and 12 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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");
}
}

View File

@ -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 );