@Test public void readTikaConfigurationShouldDefaultToSecondWhenMissingUnitForCacheEvitionPeriod() throws Exception { PropertiesConfiguration configuration = newConfiguration(); configuration.read(new StringReader( "tika.enabled=true\n" + "tika.host=172.0.0.5\n" + "tika.port=889\n" + "tika.timeoutInMillis=500\n" + "tika.cache.eviction.period=3600")); assertThat(TikaConfigurationReader.readTikaConfiguration(configuration)) .isEqualTo( TikaConfiguration.builder() .enabled() .host("172.0.0.5") .port(889) .timeoutInMillis(500) .cacheEvictionPeriod(Duration.ofHours(1)) .build()); }
public static TikaConfiguration readTikaConfiguration(Configuration configuration) { Optional<Boolean> enabled = Optional.ofNullable( configuration.getBoolean(TIKA_ENABLED, null)); Optional<Boolean> cacheEnabled = Optional.ofNullable( configuration.getBoolean(TIKA_CACHE_ENABLED, null)); Optional<String> host = Optional.ofNullable( configuration.getString(TIKA_HOST, null)); Optional<Integer> port = Optional.ofNullable( configuration.getInteger(TIKA_PORT, null)); Optional<Integer> timeoutInMillis = Optional.ofNullable( configuration.getInteger(TIKA_TIMEOUT_IN_MS, null)); Optional<Duration> cacheEvictionPeriod = Optional.ofNullable( configuration.getString(TIKA_CACHE_EVICTION_PERIOD, null)) .map(rawString -> DurationParser.parse(rawString, ChronoUnit.SECONDS)); Optional<Long> cacheWeight = Optional.ofNullable( configuration.getString(TIKA_CACHE_WEIGHT_MAX, null)) .map(Throwing.function(Size::parse)) .map(Size::asBytes); Set<MimeType> contentTypeBlacklist = StreamUtils .ofNullable(configuration.getStringArray(TIKA_CONTENT_TYPE_BLACKLIST)) .map(String::trim) .map(MimeType::of) .collect(ImmutableSet.toImmutableSet()); return TikaConfiguration.builder() .enable(enabled) .host(host) .port(port) .timeoutInMillis(timeoutInMillis) .cacheEnable(cacheEnabled) .cacheEvictionPeriod(cacheEvictionPeriod) .cacheWeightInBytes(cacheWeight) .contentTypeBlacklist(contentTypeBlacklist) .build(); }
TikaConfigurationReader { public static TikaConfiguration readTikaConfiguration(Configuration configuration) { Optional<Boolean> enabled = Optional.ofNullable( configuration.getBoolean(TIKA_ENABLED, null)); Optional<Boolean> cacheEnabled = Optional.ofNullable( configuration.getBoolean(TIKA_CACHE_ENABLED, null)); Optional<String> host = Optional.ofNullable( configuration.getString(TIKA_HOST, null)); Optional<Integer> port = Optional.ofNullable( configuration.getInteger(TIKA_PORT, null)); Optional<Integer> timeoutInMillis = Optional.ofNullable( configuration.getInteger(TIKA_TIMEOUT_IN_MS, null)); Optional<Duration> cacheEvictionPeriod = Optional.ofNullable( configuration.getString(TIKA_CACHE_EVICTION_PERIOD, null)) .map(rawString -> DurationParser.parse(rawString, ChronoUnit.SECONDS)); Optional<Long> cacheWeight = Optional.ofNullable( configuration.getString(TIKA_CACHE_WEIGHT_MAX, null)) .map(Throwing.function(Size::parse)) .map(Size::asBytes); Set<MimeType> contentTypeBlacklist = StreamUtils .ofNullable(configuration.getStringArray(TIKA_CONTENT_TYPE_BLACKLIST)) .map(String::trim) .map(MimeType::of) .collect(ImmutableSet.toImmutableSet()); return TikaConfiguration.builder() .enable(enabled) .host(host) .port(port) .timeoutInMillis(timeoutInMillis) .cacheEnable(cacheEnabled) .cacheEvictionPeriod(cacheEvictionPeriod) .cacheWeightInBytes(cacheWeight) .contentTypeBlacklist(contentTypeBlacklist) .build(); } }
TikaConfigurationReader { public static TikaConfiguration readTikaConfiguration(Configuration configuration) { Optional<Boolean> enabled = Optional.ofNullable( configuration.getBoolean(TIKA_ENABLED, null)); Optional<Boolean> cacheEnabled = Optional.ofNullable( configuration.getBoolean(TIKA_CACHE_ENABLED, null)); Optional<String> host = Optional.ofNullable( configuration.getString(TIKA_HOST, null)); Optional<Integer> port = Optional.ofNullable( configuration.getInteger(TIKA_PORT, null)); Optional<Integer> timeoutInMillis = Optional.ofNullable( configuration.getInteger(TIKA_TIMEOUT_IN_MS, null)); Optional<Duration> cacheEvictionPeriod = Optional.ofNullable( configuration.getString(TIKA_CACHE_EVICTION_PERIOD, null)) .map(rawString -> DurationParser.parse(rawString, ChronoUnit.SECONDS)); Optional<Long> cacheWeight = Optional.ofNullable( configuration.getString(TIKA_CACHE_WEIGHT_MAX, null)) .map(Throwing.function(Size::parse)) .map(Size::asBytes); Set<MimeType> contentTypeBlacklist = StreamUtils .ofNullable(configuration.getStringArray(TIKA_CONTENT_TYPE_BLACKLIST)) .map(String::trim) .map(MimeType::of) .collect(ImmutableSet.toImmutableSet()); return TikaConfiguration.builder() .enable(enabled) .host(host) .port(port) .timeoutInMillis(timeoutInMillis) .cacheEnable(cacheEnabled) .cacheEvictionPeriod(cacheEvictionPeriod) .cacheWeightInBytes(cacheWeight) .contentTypeBlacklist(contentTypeBlacklist) .build(); }  }
TikaConfigurationReader { public static TikaConfiguration readTikaConfiguration(Configuration configuration) { Optional<Boolean> enabled = Optional.ofNullable( configuration.getBoolean(TIKA_ENABLED, null)); Optional<Boolean> cacheEnabled = Optional.ofNullable( configuration.getBoolean(TIKA_CACHE_ENABLED, null)); Optional<String> host = Optional.ofNullable( configuration.getString(TIKA_HOST, null)); Optional<Integer> port = Optional.ofNullable( configuration.getInteger(TIKA_PORT, null)); Optional<Integer> timeoutInMillis = Optional.ofNullable( configuration.getInteger(TIKA_TIMEOUT_IN_MS, null)); Optional<Duration> cacheEvictionPeriod = Optional.ofNullable( configuration.getString(TIKA_CACHE_EVICTION_PERIOD, null)) .map(rawString -> DurationParser.parse(rawString, ChronoUnit.SECONDS)); Optional<Long> cacheWeight = Optional.ofNullable( configuration.getString(TIKA_CACHE_WEIGHT_MAX, null)) .map(Throwing.function(Size::parse)) .map(Size::asBytes); Set<MimeType> contentTypeBlacklist = StreamUtils .ofNullable(configuration.getStringArray(TIKA_CONTENT_TYPE_BLACKLIST)) .map(String::trim) .map(MimeType::of) .collect(ImmutableSet.toImmutableSet()); return TikaConfiguration.builder() .enable(enabled) .host(host) .port(port) .timeoutInMillis(timeoutInMillis) .cacheEnable(cacheEnabled) .cacheEvictionPeriod(cacheEvictionPeriod) .cacheWeightInBytes(cacheWeight) .contentTypeBlacklist(contentTypeBlacklist) .build(); }  static TikaConfiguration readTikaConfiguration(Configuration configuration); }
TikaConfigurationReader { public static TikaConfiguration readTikaConfiguration(Configuration configuration) { Optional<Boolean> enabled = Optional.ofNullable( configuration.getBoolean(TIKA_ENABLED, null)); Optional<Boolean> cacheEnabled = Optional.ofNullable( configuration.getBoolean(TIKA_CACHE_ENABLED, null)); Optional<String> host = Optional.ofNullable( configuration.getString(TIKA_HOST, null)); Optional<Integer> port = Optional.ofNullable( configuration.getInteger(TIKA_PORT, null)); Optional<Integer> timeoutInMillis = Optional.ofNullable( configuration.getInteger(TIKA_TIMEOUT_IN_MS, null)); Optional<Duration> cacheEvictionPeriod = Optional.ofNullable( configuration.getString(TIKA_CACHE_EVICTION_PERIOD, null)) .map(rawString -> DurationParser.parse(rawString, ChronoUnit.SECONDS)); Optional<Long> cacheWeight = Optional.ofNullable( configuration.getString(TIKA_CACHE_WEIGHT_MAX, null)) .map(Throwing.function(Size::parse)) .map(Size::asBytes); Set<MimeType> contentTypeBlacklist = StreamUtils .ofNullable(configuration.getStringArray(TIKA_CONTENT_TYPE_BLACKLIST)) .map(String::trim) .map(MimeType::of) .collect(ImmutableSet.toImmutableSet()); return TikaConfiguration.builder() .enable(enabled) .host(host) .port(port) .timeoutInMillis(timeoutInMillis) .cacheEnable(cacheEnabled) .cacheEvictionPeriod(cacheEvictionPeriod) .cacheWeightInBytes(cacheWeight) .contentTypeBlacklist(contentTypeBlacklist) .build(); }  static TikaConfiguration readTikaConfiguration(Configuration configuration); static final String TIKA_ENABLED; static final String TIKA_CACHE_ENABLED; static final String TIKA_HOST; static final String TIKA_PORT; static final String TIKA_TIMEOUT_IN_MS; static final String TIKA_CACHE_EVICTION_PERIOD; static final String TIKA_CACHE_WEIGHT_MAX; static final String TIKA_CONTENT_TYPE_BLACKLIST; }