public class ParsingReader extends Reader
Parser
(AutoDetectParser
by default) to parse the text content from
a given input stream. The BodyContentHandler
class and a pipe
is used to convert the push-based SAX event stream to the pull-based
character stream defined by the Reader
interface.Constructor and Description |
---|
ParsingReader(File file)
Creates a reader for the text content of the given file.
|
ParsingReader(InputStream stream)
Creates a reader for the text content of the given binary stream.
|
ParsingReader(InputStream stream,
String name)
Creates a reader for the text content of the given binary stream
with the given name.
|
ParsingReader(Parser parser,
InputStream stream,
Metadata metadata,
ParseContext context)
Creates a reader for the text content of the given binary stream
with the given document metadata.
|
ParsingReader(Parser parser,
InputStream stream,
Metadata metadata,
ParseContext context,
Executor executor)
Creates a reader for the text content of the given binary stream
with the given document metadata.
|
ParsingReader(Path path)
Creates a reader for the text content of the file at the given path.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the read end of the pipe.
|
int |
read(char[] cbuf,
int off,
int len)
Reads parsed text from the pipe connected to the parsing thread.
|
public ParsingReader(InputStream stream) throws IOException
stream
- binary streamIOException
- if the document can not be parsedpublic ParsingReader(InputStream stream, String name) throws IOException
stream
- binary streamname
- document nameIOException
- if the document can not be parsedpublic ParsingReader(Path path) throws IOException
path
- pathFileNotFoundException
- if the given file does not existIOException
- if the document can not be parsedpublic ParsingReader(File file) throws FileNotFoundException, IOException
file
- fileFileNotFoundException
- if the given file does not existIOException
- if the document can not be parsedParsingReader(Path)
public ParsingReader(Parser parser, InputStream stream, Metadata metadata, ParseContext context) throws IOException
The created reader will be responsible for closing the given stream.
The stream and any associated resources will be closed at or before
the time when the close()
method is called on this reader.
parser
- parser instancestream
- binary streammetadata
- document metadataIOException
- if the document can not be parsedpublic ParsingReader(Parser parser, InputStream stream, Metadata metadata, ParseContext context, Executor executor) throws IOException
Reader
interface.
The created reader will be responsible for closing the given stream.
The stream and any associated resources will be closed at or before
the time when the close()
method is called on this reader.
parser
- parser instancestream
- binary streammetadata
- document metadatacontext
- parsing contextexecutor
- executor for the parsing taskIOException
- if the document can not be parsedpublic int read(char[] cbuf, int off, int len) throws IOException
read
in class Reader
cbuf
- character bufferoff
- start offset within the bufferlen
- maximum number of characters to readIOException
- if the parsing thread has failed or
if for some reason the pipe does not work properlypublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Reader
IOException
- if the pipe can not be closedCopyright © 2007–2015 The Apache Software Foundation. All rights reserved.