@Test void deserializerShouldTakeFirstNodeWhenSeveral() throws Exception { String expectedExtractedContent = "content A"; TikaTextExtractor textExtractor = new TikaTextExtractor( new RecordingMetricFactory(), (inputStream, contentType) -> Optional.of(new ByteArrayInputStream(("[{\"X-TIKA:content\": \"" + expectedExtractedContent + "\"}, " + "{\"X-TIKA:content\": \"content B\"}]") .getBytes(StandardCharsets.UTF_8)))); InputStream inputStream = new ByteArrayInputStream("toto".getBytes(StandardCharsets.UTF_8)); ParsedContent parsedContent = textExtractor.extractContent(inputStream, ContentType.of("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")); assertThat(parsedContent.getTextualContent()).contains(expectedExtractedContent); }
@Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { if (contentType.mediaType().equals(TEXT)) { return jsoupTextExtractor.extractContent(inputStream, contentType); } return metricFactory.decorateSupplierWithTimerMetric("tikaTextExtraction", Throwing.supplier( () -> performContentExtraction(inputStream, contentType)) .sneakyThrow()); }
TikaTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { if (contentType.mediaType().equals(TEXT)) { return jsoupTextExtractor.extractContent(inputStream, contentType); } return metricFactory.decorateSupplierWithTimerMetric("tikaTextExtraction", Throwing.supplier( () -> performContentExtraction(inputStream, contentType)) .sneakyThrow()); } }
TikaTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { if (contentType.mediaType().equals(TEXT)) { return jsoupTextExtractor.extractContent(inputStream, contentType); } return metricFactory.decorateSupplierWithTimerMetric("tikaTextExtraction", Throwing.supplier( () -> performContentExtraction(inputStream, contentType)) .sneakyThrow()); } @Inject  TikaTextExtractor(MetricFactory metricFactory, TikaHttpClient tikaHttpClient); }
TikaTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { if (contentType.mediaType().equals(TEXT)) { return jsoupTextExtractor.extractContent(inputStream, contentType); } return metricFactory.decorateSupplierWithTimerMetric("tikaTextExtraction", Throwing.supplier( () -> performContentExtraction(inputStream, contentType)) .sneakyThrow()); } @Inject  TikaTextExtractor(MetricFactory metricFactory, TikaHttpClient tikaHttpClient); @Override ParsedContent extractContent(InputStream inputStream, ContentType contentType); ParsedContent performContentExtraction(InputStream inputStream, ContentType contentType); }
TikaTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { if (contentType.mediaType().equals(TEXT)) { return jsoupTextExtractor.extractContent(inputStream, contentType); } return metricFactory.decorateSupplierWithTimerMetric("tikaTextExtraction", Throwing.supplier( () -> performContentExtraction(inputStream, contentType)) .sneakyThrow()); } @Inject  TikaTextExtractor(MetricFactory metricFactory, TikaHttpClient tikaHttpClient); @Override ParsedContent extractContent(InputStream inputStream, ContentType contentType); ParsedContent performContentExtraction(InputStream inputStream, ContentType contentType);  }