class 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;
			}
		}
	}

}