Package org.apache.tika.parser.csv
Class TextAndCSVParser
- java.lang.Object
-
- org.apache.tika.parser.AbstractParser
-
- org.apache.tika.parser.AbstractEncodingDetectorParser
-
- org.apache.tika.parser.csv.TextAndCSVParser
-
- All Implemented Interfaces:
Serializable,org.apache.tika.parser.Parser
public class TextAndCSVParser extends org.apache.tika.parser.AbstractEncodingDetectorParserUnless theTikaCoreProperties.CONTENT_TYPE_USER_OVERRIDEis set, this parser tries to assess whether the file is a text file, csv or tsv. If the detector detects regularity in column numbers and/or encapsulated cells, this parser will apply theCSVParser; otherwise, it will treat the contents as text.If there is a csv parse exception during detection, the parser sets the
HttpHeaders.CONTENT_TYPEtoMediaType.TEXT_PLAINand treats the file asMediaType.TEXT_PLAIN.If there is a csv parse exception during the parse, the parser writes what's left of the stream as if it were text and then throws an exception. As of this writing, the content that was buffered by the underlying
CSVParseris lost.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.tika.metadata.PropertyDELIMITER_PROPERTYstatic org.apache.tika.metadata.PropertyNUM_COLUMNSIf the file is detected as a csv/tsv, this is the number of columns in the first row.static org.apache.tika.metadata.PropertyNUM_ROWSIf the file is detected as a csv/tsv, this is the number of rows if the file is successfully read (e.g.
-
Constructor Summary
Constructors Constructor Description TextAndCSVParser()TextAndCSVParser(org.apache.tika.detect.EncodingDetector encodingDetector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<org.apache.tika.mime.MediaType>getSupportedTypes(org.apache.tika.parser.ParseContext context)voidparse(InputStream stream, ContentHandler handler, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext context)
-
-
-
Field Detail
-
DELIMITER_PROPERTY
public static final org.apache.tika.metadata.Property DELIMITER_PROPERTY
-
NUM_COLUMNS
public static final org.apache.tika.metadata.Property NUM_COLUMNS
If the file is detected as a csv/tsv, this is the number of columns in the first row.
-
NUM_ROWS
public static final org.apache.tika.metadata.Property NUM_ROWS
If the file is detected as a csv/tsv, this is the number of rows if the file is successfully read (e.g. no encapsulation exceptions, etc).
-
-
Method Detail
-
getSupportedTypes
public Set<org.apache.tika.mime.MediaType> getSupportedTypes(org.apache.tika.parser.ParseContext context)
-
parse
public void parse(InputStream stream, ContentHandler handler, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext context) throws IOException, SAXException, org.apache.tika.exception.TikaException
- Throws:
IOExceptionSAXExceptionorg.apache.tika.exception.TikaException
-
-