-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExternalUtf8ContentFilterFactory: Don't convert pointer offsets to char
Instead, calculate difference while we read through the input during parsing. This saves us a whole pass through the input files, which should improve performance for non-filesystem based sources (where we don't have the page cache to help us out).
- Loading branch information
Showing
7 changed files
with
561 additions
and
171 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/com/github/dbmdz/solrocr/lucene/filters/ByteSeekableReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.github.dbmdz.solrocr.lucene.filters; | ||
|
||
import com.github.dbmdz.solrocr.reader.StreamDecoder; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.nio.channels.SeekableByteChannel; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* A Reader implementation that reads from a SeekableByteChannel and allows repositioning the | ||
* reader. | ||
*/ | ||
public class ByteSeekableReader extends Reader { | ||
private final SeekableByteChannel channel; | ||
private StreamDecoder decoder; | ||
|
||
public ByteSeekableReader(SeekableByteChannel channel) { | ||
this.channel = channel; | ||
this.decoder = StreamDecoder.forDecoder(channel, StandardCharsets.UTF_8.newDecoder(), -1); | ||
} | ||
|
||
@Override | ||
public int read(char[] cbuf, int off, int len) throws IOException { | ||
return this.decoder.read(cbuf, off, len); | ||
} | ||
|
||
/** Return the current byte position in the underlying channel. */ | ||
public int position() throws IOException { | ||
return (int) this.channel.position(); | ||
} | ||
|
||
/** | ||
* Reposition the reader to the given byte position. | ||
* | ||
* <p>This will also reset the decoder. | ||
*/ | ||
public void position(int newPosition) throws IOException { | ||
this.channel.position(newPosition); | ||
this.decoder = StreamDecoder.forDecoder(channel, StandardCharsets.UTF_8.newDecoder(), -1); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
this.channel.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.