diff --git a/client/src/main/java/io/split/client/SplitFactoryImpl.java b/client/src/main/java/io/split/client/SplitFactoryImpl.java index 8dff2c79d..88413bdbd 100644 --- a/client/src/main/java/io/split/client/SplitFactoryImpl.java +++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java @@ -34,8 +34,8 @@ import io.split.client.utils.FileInputStreamProvider; import io.split.client.utils.FileTypeEnum; import io.split.client.utils.InputStreamProvider; -import io.split.client.utils.InputStreamProviderImp; import io.split.client.utils.SDKMetadata; +import io.split.client.utils.StaticContentInputStreamProvider; import io.split.engine.SDKReadinessGates; import io.split.engine.common.ConsumerSyncManager; import io.split.engine.common.ConsumerSynchronizer; @@ -655,7 +655,7 @@ private SplitChangeFetcher createSplitChangeFetcher(SplitClientConfig splitClien fileType = getFileTypeFromFileName(splitFile); inputStreamProvider = new FileInputStreamProvider(splitFile); } else { - inputStreamProvider = new InputStreamProviderImp(inputStream); + inputStreamProvider = new StaticContentInputStreamProvider(inputStream); } try { switch (fileType){ diff --git a/client/src/main/java/io/split/client/utils/InputStreamProviderImp.java b/client/src/main/java/io/split/client/utils/InputStreamProviderImp.java deleted file mode 100644 index 4b945fcd3..000000000 --- a/client/src/main/java/io/split/client/utils/InputStreamProviderImp.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.split.client.utils; - -import io.split.client.exceptions.InputStreamProviderException; - -import java.io.InputStream; - -public class InputStreamProviderImp implements InputStreamProvider { - private final InputStream _inputStream; - - public InputStreamProviderImp(InputStream inputStream){ - _inputStream = inputStream; - } - - @Override - public InputStream get() throws InputStreamProviderException { - return _inputStream; - } -} \ No newline at end of file diff --git a/client/src/main/java/io/split/client/utils/StaticContentInputStreamProvider.java b/client/src/main/java/io/split/client/utils/StaticContentInputStreamProvider.java new file mode 100644 index 000000000..d129b77c8 --- /dev/null +++ b/client/src/main/java/io/split/client/utils/StaticContentInputStreamProvider.java @@ -0,0 +1,26 @@ +package io.split.client.utils; + +import io.split.client.exceptions.InputStreamProviderException; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + +public class StaticContentInputStreamProvider implements InputStreamProvider { + + private final String _streamContents; + + public StaticContentInputStreamProvider(InputStream inputStream){ + _streamContents = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)) + .lines() + .collect(Collectors.joining("\n")); + } + + @Override + public InputStream get() throws InputStreamProviderException { + return new ByteArrayInputStream(_streamContents.getBytes()); + } +} diff --git a/client/src/test/java/io/split/client/JsonLocalhostSplitChangeFetcherTest.java b/client/src/test/java/io/split/client/JsonLocalhostSplitChangeFetcherTest.java index e9a3c5cdd..c355734aa 100644 --- a/client/src/test/java/io/split/client/JsonLocalhostSplitChangeFetcherTest.java +++ b/client/src/test/java/io/split/client/JsonLocalhostSplitChangeFetcherTest.java @@ -6,7 +6,7 @@ import io.split.client.dtos.Status; import io.split.client.utils.FileInputStreamProvider; import io.split.client.utils.InputStreamProvider; -import io.split.client.utils.InputStreamProviderImp; +import io.split.client.utils.StaticContentInputStreamProvider; import io.split.engine.common.FetchOptions; import org.junit.Assert; import org.junit.Rule; @@ -35,7 +35,7 @@ public class JsonLocalhostSplitChangeFetcherTest { @Test public void testParseSplitChange() throws FileNotFoundException { InputStream inputStream = new FileInputStream("src/test/resources/split_init.json"); - InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream); + InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream); JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); FetchOptions fetchOptions = Mockito.mock(FetchOptions.class); @@ -50,7 +50,7 @@ public void testParseSplitChange() throws FileNotFoundException { @Test public void testSinceAndTillSanitization() throws FileNotFoundException { InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangeTillSanitization.json"); - InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream); + InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream); JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); FetchOptions fetchOptions = Mockito.mock(FetchOptions.class); @@ -63,7 +63,7 @@ public void testSinceAndTillSanitization() throws FileNotFoundException { @Test public void testSplitChangeWithoutSplits() throws FileNotFoundException { InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangeWithoutSplits.json"); - InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream); + InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream); JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); FetchOptions fetchOptions = Mockito.mock(FetchOptions.class); @@ -75,7 +75,7 @@ public void testSplitChangeWithoutSplits() throws FileNotFoundException { @Test public void testSplitChangeSplitsToSanitize() throws FileNotFoundException { InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangeSplitsToSanitize.json"); - InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream); + InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream); JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); FetchOptions fetchOptions = Mockito.mock(FetchOptions.class); @@ -92,7 +92,7 @@ public void testSplitChangeSplitsToSanitize() throws FileNotFoundException { @Test public void testSplitChangeSplitsToSanitizeMatchersNull() throws FileNotFoundException { InputStream inputStream = new FileInputStream("src/test/resources/sanitizer/splitChangerMatchersNull.json"); - InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream); + InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream); JsonLocalhostSplitChangeFetcher localhostSplitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); FetchOptions fetchOptions = Mockito.mock(FetchOptions.class); diff --git a/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java b/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java index 50ce80f2f..32ba6fa0b 100644 --- a/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java +++ b/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java @@ -4,7 +4,7 @@ import io.split.client.LocalhostSegmentChangeFetcher; import io.split.client.JsonLocalhostSplitChangeFetcher; import io.split.client.utils.InputStreamProvider; -import io.split.client.utils.InputStreamProviderImp; +import io.split.client.utils.StaticContentInputStreamProvider; import io.split.engine.common.FetchOptions; import io.split.engine.experiments.SplitChangeFetcher; import io.split.engine.experiments.SplitFetcher; @@ -155,7 +155,7 @@ public void testLocalhostSegmentChangeFetcher() throws InterruptedException, Fil SplitCache splitCacheProducer = new InMemoryCacheImp(); InputStream inputStream = new FileInputStream("src/test/resources/split_init.json"); - InputStreamProvider inputStreamProvider = new InputStreamProviderImp(inputStream); + InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream); SplitChangeFetcher splitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); SplitParser splitParser = new SplitParser(); FetchOptions fetchOptions = new FetchOptions.Builder().build();