CSVDetector implements Detector { @Override public Format detect(Metadata metadata, TikaInputStream inputStream) throws IOException { Format result = detectText(metadata, inputStream); if (result == null) { inputStream.mark(FormatUtils.META_TAG_BUFFER_SIZE); byte[] buffer = new byte[FormatUtils.META_TAG_BUFFER_SIZE]; int n = 0; for (int m = inputStream.read(buffer); m != -1 && n < buffer.length; m = inputStream.read(buffer, n, buffer.length - n)) { n += m; } inputStream.reset(); String head = FormatUtils.readFromBuffer(buffer, 0, n); try (InputStream stream = TikaInputStream.get(IOUtils.toInputStream(head))) { result = detectText(new Metadata(), stream); } } return result; }  @Override Format detect(Metadata metadata, TikaInputStream inputStream);  }
@Test public void should_detect_CSV_format_and_encoding() throws IOException { try (InputStream inputStream = this.getClass().getResourceAsStream("standard.csv")) { Format actual = csvDetector.detect(inputStream); Assert.assertNotNull(actual); assertTrue(actual.getFormatFamily() instanceof CSVFormatFamily); assertEquals("ISO-8859-1", actual.getEncoding()); } }
@Test(expected = IllegalArgumentException.class) public void should_not_read_null_input_stream() throws Exception { csvDetector.detect(null); }