Class FileDetector
java.lang.Object
com.northconcepts.datapipeline.foundations.file.FileDetector
Detects the
FileType of a file or stream from its name's extension or, failing that, by sampling its first
bytes.-
Constructor Summary
ConstructorsConstructorDescriptionFileDetector(File file) FileDetector(InputStream inputStream) Creates a detector that samples the stream's content, closing the stream once it is read.FileDetector(InputStream inputStream, String filename) Creates a detector that checks the file name's extension first and otherwise samples the stream, closing it once read. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Returns the sampled bytes (up to 2048, seegetBufferSize()), or null if the content has not been read.intReturns the number of valid bytes ingetBuffer(): -1 for empty content and 0 before the content is read.intReturns the separator (comma, tab, pipe, semicolon or caret) that outnumbers all the others combined in CSV content, or -1 if the type is not CSV or none does.getFile()Returns the file being examined, or null when reading from a stream.Returns the detected type, from the name's extension if it matches one exactly, otherwise by sampling the content.int[]Returns the count of each byte value (256 entries) in the sample, or null if the content has not been read.booleanisBinary()Indicates if the sample contains control characters (other than tab, CR and LF) or DEL; false until the content is read.
-
Constructor Details
-
FileDetector
-
FileDetector
Creates a detector that samples the stream's content, closing the stream once it is read. -
FileDetector
Creates a detector that checks the file name's extension first and otherwise samples the stream, closing it once read.
-
-
Method Details
-
getFile
Returns the file being examined, or null when reading from a stream. -
getBuffer
public byte[] getBuffer()Returns the sampled bytes (up to 2048, seegetBufferSize()), or null if the content has not been read. -
getBufferSize
public int getBufferSize()Returns the number of valid bytes ingetBuffer(): -1 for empty content and 0 before the content is read. -
getHistogram
public int[] getHistogram()Returns the count of each byte value (256 entries) in the sample, or null if the content has not been read. -
isBinary
public boolean isBinary()Indicates if the sample contains control characters (other than tab, CR and LF) or DEL; false until the content is read. -
getFileType
Returns the detected type, from the name's extension if it matches one exactly, otherwise by sampling the content. Sampled binary data is reported as XLSX, XLS or BINARY and text as XML, JSON, CSV or TEXT. -
getCsvFieldSeparator
public int getCsvFieldSeparator()Returns the separator (comma, tab, pipe, semicolon or caret) that outnumbers all the others combined in CSV content, or -1 if the type is not CSV or none does.
-