DocumentTikaParser { public static Optional<String> parse(final InputStream input, final Metadata metadata, final int limit) throws TikaException, IOException { try { String content = TIKA_INSTANCE.parseToString(input, metadata, limit); if (isEmpty(content)) { return Optional.empty(); } content = StringUtils.trim(content); return Optional.of(content); } catch (Exception e) { Throwable cause = e.getCause(); if (cause instanceof TikaException) { throw (TikaException) cause; } else if (cause instanceof IOException) { throw (IOException) cause; } else { throw e; } } }  static Optional<String> parse(final InputStream input, final Metadata metadata, final int limit);  }
@Test public void testTika() throws TikaException, IOException { Buffer buffer = getBuffer("/testfiles/test.pdf"); byte[] data = buffer.getBytes(); Metadata metadata = new Metadata(); int limit = 10000; String content = DocumentTikaParser.parse(new ByteArrayInputStream(data), metadata, limit).get(); System.out.println(content); System.out.println(metadata.toString()); }