@Test public void testLoadNotExists() { FileConfigSource configSource = ConfigSources.file("application.unknown") .build(); assertThat(configSource.load(), is(Optional.empty())); }
@Override public Optional<ConfigParser.Content> load() throws ConfigException { LOGGER.fine(() -> String.format("Getting content from '%s'", filePath)); Optional<DataAndDigest> dataAndDigest = FileSourceHelper.readDataAndDigest(filePath); if (dataAndDigest.isEmpty()) { return Optional.empty(); } DataAndDigest dad = dataAndDigest.get(); InputStream dataStream = new ByteArrayInputStream(dad.data()); var builder = ConfigParser.Content.builder() .stamp(dad.digest()) .data(dataStream); MediaTypes.detectType(filePath).ifPresent(builder::mediaType); return Optional.of(builder.build()); }
FileConfigSource extends AbstractConfigSource implements WatchableSource<Path>, ParsableSource, PollableSource<byte[]> { @Override public Optional<ConfigParser.Content> load() throws ConfigException { LOGGER.fine(() -> String.format("Getting content from '%s'", filePath)); Optional<DataAndDigest> dataAndDigest = FileSourceHelper.readDataAndDigest(filePath); if (dataAndDigest.isEmpty()) { return Optional.empty(); } DataAndDigest dad = dataAndDigest.get(); InputStream dataStream = new ByteArrayInputStream(dad.data()); var builder = ConfigParser.Content.builder() .stamp(dad.digest()) .data(dataStream); MediaTypes.detectType(filePath).ifPresent(builder::mediaType); return Optional.of(builder.build()); } }
FileConfigSource extends AbstractConfigSource implements WatchableSource<Path>, ParsableSource, PollableSource<byte[]> { @Override public Optional<ConfigParser.Content> load() throws ConfigException { LOGGER.fine(() -> String.format("Getting content from '%s'", filePath)); Optional<DataAndDigest> dataAndDigest = FileSourceHelper.readDataAndDigest(filePath); if (dataAndDigest.isEmpty()) { return Optional.empty(); } DataAndDigest dad = dataAndDigest.get(); InputStream dataStream = new ByteArrayInputStream(dad.data()); var builder = ConfigParser.Content.builder() .stamp(dad.digest()) .data(dataStream); MediaTypes.detectType(filePath).ifPresent(builder::mediaType); return Optional.of(builder.build()); } FileConfigSource(Builder builder); }
FileConfigSource extends AbstractConfigSource implements WatchableSource<Path>, ParsableSource, PollableSource<byte[]> { @Override public Optional<ConfigParser.Content> load() throws ConfigException { LOGGER.fine(() -> String.format("Getting content from '%s'", filePath)); Optional<DataAndDigest> dataAndDigest = FileSourceHelper.readDataAndDigest(filePath); if (dataAndDigest.isEmpty()) { return Optional.empty(); } DataAndDigest dad = dataAndDigest.get(); InputStream dataStream = new ByteArrayInputStream(dad.data()); var builder = ConfigParser.Content.builder() .stamp(dad.digest()) .data(dataStream); MediaTypes.detectType(filePath).ifPresent(builder::mediaType); return Optional.of(builder.build()); } FileConfigSource(Builder builder); static FileConfigSource create(Config metaConfig); static Builder builder(); @Override boolean isModified(byte[] stamp); @Override Path target(); @Override Optional<ConfigParser.Content> load(); @Override Optional<ConfigParser> parser(); @Override Optional<String> mediaType(); @Override Optional<PollingStrategy> pollingStrategy(); @Override Optional<ChangeWatcher<Object>> changeWatcher(); @Override boolean exists(); }
FileConfigSource extends AbstractConfigSource implements WatchableSource<Path>, ParsableSource, PollableSource<byte[]> { @Override public Optional<ConfigParser.Content> load() throws ConfigException { LOGGER.fine(() -> String.format("Getting content from '%s'", filePath)); Optional<DataAndDigest> dataAndDigest = FileSourceHelper.readDataAndDigest(filePath); if (dataAndDigest.isEmpty()) { return Optional.empty(); } DataAndDigest dad = dataAndDigest.get(); InputStream dataStream = new ByteArrayInputStream(dad.data()); var builder = ConfigParser.Content.builder() .stamp(dad.digest()) .data(dataStream); MediaTypes.detectType(filePath).ifPresent(builder::mediaType); return Optional.of(builder.build()); } FileConfigSource(Builder builder); static FileConfigSource create(Config metaConfig); static Builder builder(); @Override boolean isModified(byte[] stamp); @Override Path target(); @Override Optional<ConfigParser.Content> load(); @Override Optional<ConfigParser> parser(); @Override Optional<String> mediaType(); @Override Optional<PollingStrategy> pollingStrategy(); @Override Optional<ChangeWatcher<Object>> changeWatcher(); @Override boolean exists();  }