YangTextSchemaSource is a CharSource 01/105801/9
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 3 May 2023 01:04:35 +0000 (03:04 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 13 Jun 2023 08:26:52 +0000 (08:26 +0000)
YANG text is inherently a plain text, without the ability to detect the
actual encoding. This patch makes the baseline interface a CharSource,
pushing the control to users and defaulting to UTF_8.

This does not extend to YinTextSchemaSource, as XML provides for
explicit control over the character set that governs the document.

JIRA: YANGTOOLS-1508
Change-Id: I2875bb5850def25a0e9e4c9ce1921f5be3a5c77f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangStatementStreamSource.java
parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSchemaSource.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ScannedDependency.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYangTextSchemaSource.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/StringYangTextSchemaSource.java [moved from yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ImmediateYangTextSchemaSource.java with 60% similarity]
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextFileSchemaSource.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java
yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java
yang/yang-repo-fs/src/test/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCacheIntegrationTest.java
yang/yang-repo-fs/src/test/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCacheTest.java
yang/yang-repo-spi/src/test/java/org/opendaylight/yangtools/yang/model/repo/spi/GuavaSchemaSourceCacheTest.java
yang/yang-repo-spi/src/test/java/org/opendaylight/yangtools/yang/model/repo/spi/SoftSchemaSourceCacheTest.java

index bb6e4d40e3485afa24701a99e09bc101eaddfc77..8e087bf256bc535217edf8c4dc5fe7c7069e7b87 100644 (file)
@@ -134,7 +134,7 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem
                 }
             }
 
-            text = YangTextSchemaSource.delegateForByteSource(parsedId, source);
+            text = YangTextSchemaSource.delegateForCharSource(parsedId, source);
         } else {
             text = source;
         }
index 3b74853103c9576e273a6011ebbf8869b2fd25ca..cfabdfbfb2b6d90642128d726b026e2dd0e867fd 100644 (file)
@@ -12,7 +12,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.Reader;
 import org.antlr.v4.runtime.CharStreams;
 import org.antlr.v4.runtime.CommonTokenStream;
 import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
@@ -132,14 +132,14 @@ public final class YangStatementStreamSource extends AbstractSimpleIdentifiable<
 
     static StatementContext parseYangSource(final YangTextSchemaSource source)
             throws IOException, YangSyntaxErrorException {
-        try (InputStream stream = source.openStream()) {
-            return parseYangSource(source.getIdentifier(), stream);
+        try (var reader = source.openStream()) {
+            return parseYangSource(source.getIdentifier(), reader);
         }
     }
 
-    private static StatementContext parseYangSource(final SourceIdentifier source, final InputStream stream)
+    private static StatementContext parseYangSource(final SourceIdentifier source, final Reader stream)
             throws IOException, YangSyntaxErrorException {
-        final YangStatementLexer lexer = new CompactYangStatementLexer(CharStreams.fromStream(stream));
+        final YangStatementLexer lexer = new CompactYangStatementLexer(CharStreams.fromReader(stream));
         final YangStatementParser parser = new YangStatementParser(new CommonTokenStream(lexer));
         // disconnect from console error output
         lexer.removeErrorListeners();
index 43347516b3a26c3f4988cb8ca0245aa5e58b33a9..aa50efb232173aa78decc0ce59c00b7634497fdb 100644 (file)
@@ -10,10 +10,7 @@ package org.opendaylight.yangtools.yang.test.util;
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.io.CharSource;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.StringReader;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.UnresolvedQName;
@@ -57,8 +54,8 @@ final class LiteralYangTextSchemaSource extends YangTextSchemaSource {
     }
 
     @Override
-    public InputStream openStream() throws IOException {
-        return CharSource.wrap(sourceString).asByteSource(StandardCharsets.UTF_8).openStream();
+    public StringReader openStream() {
+        return new StringReader(sourceString);
     }
 
     @Override
index 01e06e454ebb638ff40aae65a6092ea5b5cf9c63..177bd4bfb67f355da34429d3990c6f157bd9a9a5 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.io.CharStreams;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.IOException;
 import java.io.Reader;
-import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -98,7 +97,7 @@ final class ProcessorModuleReactor {
 
         for (ScannedDependency dependency : dependencies) {
             for (YangTextSchemaSource s : dependency.sources()) {
-                try (Reader reader = s.asCharSource(StandardCharsets.UTF_8).openStream()) {
+                try (Reader reader = s.openStream()) {
                     final String contents = CharStreams.toString(reader);
                     byContent.putIfAbsent(contents, s);
                 }
index d86df7d114acc72a4db4c3f3eeedee71339aba32..3bd4b2b015cfb9f452ca8d353bcb3508c0b8d2bf 100644 (file)
@@ -19,6 +19,7 @@ import com.google.common.io.ByteSource;
 import com.google.common.io.ByteStreams;
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -62,7 +63,9 @@ abstract class ScannedDependency {
 
                     builder.add(YangTextSchemaSource.delegateForByteSource(
                         entryName.substring(entryName.lastIndexOf('/') + 1),
-                        ByteSource.wrap(ByteStreams.toByteArray(zip.getInputStream(entry)))));
+                        // FIXME: can we reasonable make this a CharSource?
+                        ByteSource.wrap(ByteStreams.toByteArray(zip.getInputStream(entry))),
+                        StandardCharsets.UTF_8));
                 }
             }
 
index 99685df218ae1e803ac2c89417aa7cdb95a69023..1ed6f6888f8bb95879c87b7ea933d9755b35bfef 100644 (file)
@@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
@@ -87,7 +88,8 @@ class YangToSourcesProcessor {
         final var stateListBuilder = ImmutableList.<FileState>builderWithExpectedSize(modelsInProject.size());
         for (var source : modelsInProject) {
             final File file = new File(withMetaInf, source.getIdentifier().toYangFilename());
-            stateListBuilder.add(FileState.ofWrittenFile(file, source::copyTo));
+            stateListBuilder.add(FileState.ofWrittenFile(file,
+                out -> source.asByteSource(StandardCharsets.UTF_8).copyTo(out)));
             LOG.debug("Created file {} for {}", file, source.getIdentifier());
         }
 
@@ -398,7 +400,7 @@ class YangToSourcesProcessor {
 
                 if (!astSource.getIdentifier().equals(textSource.getIdentifier())) {
                     // AST indicates a different source identifier, make sure we use that
-                    sourcesInProject.add(YangTextSchemaSource.delegateForByteSource(astSource.getIdentifier(),
+                    sourcesInProject.add(YangTextSchemaSource.delegateForCharSource(astSource.getIdentifier(),
                         textSource));
                 } else {
                     sourcesInProject.add(textSource);
index 26e5bc7221852adcf08138c1e132370af1c34ef5..65a7e038acbba57fd14569f4a3a227b5cb267d20 100644 (file)
@@ -10,28 +10,28 @@ package org.opendaylight.yangtools.yang.model.repo.api;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.io.ByteSource;
+import com.google.common.io.CharSource;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.Reader;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Delegator;
 
-final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator<ByteSource> {
-    private final @NonNull ByteSource delegate;
+final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator<CharSource> {
+    private final @NonNull CharSource delegate;
 
-    DelegatedYangTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
+    DelegatedYangTextSchemaSource(final SourceIdentifier identifier, final CharSource delegate) {
         super(identifier);
         this.delegate = requireNonNull(delegate);
     }
 
     @Override
-    public ByteSource getDelegate() {
+    public CharSource getDelegate() {
         return delegate;
     }
 
     @Override
-    public InputStream openStream() throws IOException {
+    public Reader openStream() throws IOException {
         return delegate.openStream();
     }
 
index 7eef2ff028ffa39b8b060fbc051cf3a6719189f2..c0cf6ec2fb6a7c4f8e9814390059986920785e8f 100644 (file)
@@ -11,8 +11,10 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Delegator;
@@ -22,10 +24,12 @@ import org.opendaylight.yangtools.concepts.Delegator;
  */
 final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements Delegator<URL> {
     private final @NonNull URL url;
+    private final @NonNull Charset charset;
 
-    ResourceYangTextSchemaSource(final SourceIdentifier identifier, final URL url) {
+    ResourceYangTextSchemaSource(final SourceIdentifier identifier, final URL url, final Charset charset) {
         super(identifier);
         this.url = requireNonNull(url);
+        this.charset = requireNonNull(charset);
     }
 
     @Override
@@ -39,8 +43,8 @@ final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements
     }
 
     @Override
-    public InputStream openStream() throws IOException {
-        return url.openStream();
+    public Reader openStream() throws IOException {
+        return new InputStreamReader(url.openStream(), charset);
     }
 
     @Override
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
+import static java.util.Objects.requireNonNull;
+
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
@@ -16,18 +18,18 @@ import org.eclipse.jdt.annotation.Nullable;
 /**
  * A {@link YangTextSchemaSource} with content readily available.
  */
-public class ImmediateYangTextSchemaSource extends YangTextSchemaSource {
+public class StringYangTextSchemaSource extends YangTextSchemaSource {
     private final @Nullable String symbolicName;
-    private final byte @NonNull [] bytes;
+    private final @NonNull String content;
 
-    public ImmediateYangTextSchemaSource(final SourceIdentifier identifier, final byte[] bytes) {
-        this(identifier, bytes, null);
+    public StringYangTextSchemaSource(final SourceIdentifier identifier, final String content) {
+        this(identifier, content, null);
     }
 
-    public ImmediateYangTextSchemaSource(final SourceIdentifier identifier, final byte[] bytes,
+    public StringYangTextSchemaSource(final SourceIdentifier identifier, final String content,
             final @Nullable String symbolicName) {
         super(identifier);
-        this.bytes = bytes.clone();
+        this.content = requireNonNull(content);
         this.symbolicName = symbolicName;
     }
 
@@ -37,7 +39,7 @@ public class ImmediateYangTextSchemaSource extends YangTextSchemaSource {
     }
 
     @Override
-    public final InputStream openStream() {
-        return new ByteArrayInputStream(bytes);
+    public final Reader openStream() {
+        return new StringReader(content);
     }
 }
index 6821e1a0164446751599d6f1945cf7480b807c2e..c17d96bd9269610b85286edc6e4e40e53ffd8414 100644 (file)
@@ -11,7 +11,9 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Optional;
@@ -25,10 +27,12 @@ import org.opendaylight.yangtools.concepts.Delegator;
  */
 final class YangTextFileSchemaSource extends YangTextSchemaSource implements Delegator<Path> {
     private final @NonNull Path path;
+    private final @NonNull Charset charset;
 
-    YangTextFileSchemaSource(final SourceIdentifier identifier, final Path path) {
+    YangTextFileSchemaSource(final SourceIdentifier identifier, final Path path, final Charset charset) {
         super(identifier);
         this.path = requireNonNull(path);
+        this.charset = requireNonNull(charset);
     }
 
     @Override
@@ -37,8 +41,8 @@ final class YangTextFileSchemaSource extends YangTextSchemaSource implements Del
     }
 
     @Override
-    public InputStream openStream() throws IOException {
-        return Files.newInputStream(path);
+    public Reader openStream() throws IOException {
+        return new InputStreamReader(Files.newInputStream(path), charset);
     }
 
     @Override
index 1300faeb71a2f0381b57fee1ecab18053ec40780..ec5a93ff9f0c7cf8b246eca9658a33564a9d489f 100644 (file)
@@ -16,10 +16,13 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.io.ByteSource;
+import com.google.common.io.CharSource;
 import com.google.common.io.Resources;
 import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import org.eclipse.jdt.annotation.NonNull;
@@ -28,7 +31,7 @@ import org.eclipse.jdt.annotation.NonNull;
  * YANG text schema source representation. Exposes an RFC6020 or RFC7950 text representation as an {@link InputStream}.
  */
 @Beta
-public abstract class YangTextSchemaSource extends ByteSource implements YangSchemaSourceRepresentation {
+public abstract class YangTextSchemaSource extends CharSource implements YangSchemaSourceRepresentation {
     private final @NonNull SourceIdentifier identifier;
 
     protected YangTextSchemaSource(final SourceIdentifier identifier) {
@@ -50,11 +53,12 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
      *
      * @param identifier SourceIdentifier of the resulting schema source
      * @param delegate Backing ByteSource instance
+     * @param charset Expected character set
      * @return A new YangTextSchemaSource
      */
     public static @NonNull YangTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
-            final ByteSource delegate) {
-        return new DelegatedYangTextSchemaSource(identifier, delegate);
+            final ByteSource delegate, final Charset charset) {
+        return delegateForCharSource(identifier, delegate.asCharSource(charset));
     }
 
     /**
@@ -67,7 +71,34 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
      * @throws IllegalArgumentException if the file name has invalid format
      */
     public static @NonNull YangTextSchemaSource delegateForByteSource(final String fileName,
-            final ByteSource delegate) {
+            final ByteSource delegate, final Charset charset) {
+        return delegateForCharSource(fileName, delegate.asCharSource(charset));
+    }
+
+    /**
+     * Create a new YangTextSchemaSource with a specific source identifier and backed
+     * by ByteSource, which provides the actual InputStreams.
+     *
+     * @param identifier SourceIdentifier of the resulting schema source
+     * @param delegate Backing CharSource instance
+     * @return A new YangTextSchemaSource
+     */
+    public static @NonNull YangTextSchemaSource delegateForCharSource(final SourceIdentifier identifier,
+            final CharSource delegate) {
+        return new DelegatedYangTextSchemaSource(identifier, delegate);
+    }
+
+    /**
+     * Create a new YangTextSchemaSource with {@link SourceIdentifier} derived from a supplied filename and backed
+     * by ByteSource, which provides the actual InputStreams.
+     *
+     * @param fileName File name
+     * @param delegate Backing CharSource instance
+     * @return A new YangTextSchemaSource
+     * @throws IllegalArgumentException if the file name has invalid format
+     */
+    public static @NonNull YangTextSchemaSource delegateForCharSource(final String fileName,
+            final CharSource delegate) {
         return new DelegatedYangTextSchemaSource(identifierFromFilename(fileName), delegate);
     }
 
@@ -94,8 +125,23 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
      * @throws IllegalArgumentException if the supplied path is not a regular file
      */
     public static @NonNull YangTextSchemaSource forPath(final Path path, final SourceIdentifier identifier) {
+        return forPath(path, identifier, StandardCharsets.UTF_8);
+    }
+
+    /**
+     * Create a new YangTextSchemaSource backed by a {@link File} and specified {@link SourceIdentifier}.
+     *
+     * @param path Backing path
+     * @param identifier Source identifier
+     * @param charset expected stream character set
+     * @return A new YangTextSchemaSource
+     * @throws NullPointerException if any argument is {@code null}
+     * @throws IllegalArgumentException if the supplied path is not a regular file
+     */
+    public static @NonNull YangTextSchemaSource forPath(final Path path, final SourceIdentifier identifier,
+            final Charset charset) {
         checkArgument(Files.isRegularFile(path), "Supplied path %s is not a regular file", path);
-        return new YangTextFileSchemaSource(identifier, path);
+        return new YangTextFileSchemaSource(identifier, path, charset);
     }
 
     /**
@@ -120,12 +166,28 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
      * @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
      */
     public static @NonNull YangTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
+        return forResource(clazz, resourceName, StandardCharsets.UTF_8);
+    }
+
+    /**
+     * Create a new {@link YangTextSchemaSource} backed by a resource by a resource available on the ClassLoader
+     * which loaded the specified class.
+     *
+     * @param clazz Class reference
+     * @param resourceName Resource name
+     * @param charset Expected character set
+     * @return A new instance.
+     * @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
+     */
+    public static @NonNull YangTextSchemaSource forResource(final Class<?> clazz, final String resourceName,
+            final Charset charset) {
         final String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
         final SourceIdentifier identifier = identifierFromFilename(fileName);
         final URL url = Resources.getResource(clazz, resourceName);
-        return new ResourceYangTextSchemaSource(identifier, url);
+        return new ResourceYangTextSchemaSource(identifier, url, charset);
     }
 
+
     /**
      * Create a new {@link YangTextSchemaSource} backed by a URL.
      *
@@ -135,9 +197,24 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
      * @throws NullPointerException if any argument is {@code null}
      */
     public static @NonNull YangTextSchemaSource forURL(final URL url, final SourceIdentifier identifier) {
-        return new ResourceYangTextSchemaSource(identifier, url);
+        return forURL(url, identifier, StandardCharsets.UTF_8);
     }
 
+    /**
+     * Create a new {@link YangTextSchemaSource} backed by a URL.
+     *
+     * @param url Backing URL
+     * @param identifier Source identifier
+     * @param charset Expected character set
+     * @return A new instance.
+     * @throws NullPointerException if any argument is {@code null}
+     */
+    public static @NonNull YangTextSchemaSource forURL(final URL url, final SourceIdentifier identifier,
+            final Charset charset) {
+        return new ResourceYangTextSchemaSource(identifier, url, charset);
+    }
+
+
     @Override
     public final SourceIdentifier getIdentifier() {
         return identifier;
index ddc0b090e93ba5983f4470469f093df2e1ac28d3..6871381fcbe615fbed67d04cf82851bf7b9336cf 100644 (file)
@@ -17,7 +17,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -238,7 +238,7 @@ public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentat
         @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE",
             justification = "https://github.com/spotbugs/spotbugs/issues/600")
         protected void storeAsType(final File file, final YangTextSchemaSource cast) {
-            try (InputStream castStream = cast.openStream()) {
+            try (var castStream = cast.asByteSource(StandardCharsets.UTF_8).openStream()) {
                 Files.copy(castStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
             } catch (final IOException e) {
                 throw new IllegalStateException("Cannot store schema source " + cast.getIdentifier() + " to " + file,
index e3a4df57b900d990e5ff7ff75dc122ea2c1b566b..f479026ef48ddd5fd92a7db57a0f35ede5e16d13 100644 (file)
@@ -20,10 +20,10 @@ import com.google.common.collect.Lists;
 import com.google.common.io.Files;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -116,8 +116,8 @@ public class FilesystemSchemaSourceCacheIntegrationTest {
                 }
 
                 @Override
-                public InputStream openStream() throws IOException {
-                    return new ByteArrayInputStream("running".getBytes(StandardCharsets.UTF_8));
+                public Reader openStream() throws IOException {
+                    return new StringReader("running");
                 }
 
                 @Override
index ef6841ea404d69c700cfcb361ff6a10658f80de5..08bbc03d34510c3f9f324281434d91ec54dec8ff 100644 (file)
@@ -24,11 +24,10 @@ import static org.mockito.Mockito.verify;
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.Collections2;
 import com.google.common.util.concurrent.ListenableFuture;
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.Reader;
+import java.io.StringReader;
 import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.Collection;
@@ -241,8 +240,8 @@ public class FilesystemSchemaSourceCacheTest {
         }
 
         @Override
-        public InputStream openStream() throws IOException {
-            return new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
+        public Reader openStream() throws IOException {
+            return new StringReader(content);
         }
 
         @Override
index 72cb5b55056edc5b88f0e9fe8bdcb185ca083225..8853b4a8cdb8fb4ef26388ea293cd239345acbd2 100644 (file)
@@ -15,9 +15,8 @@ import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -117,8 +116,8 @@ public class GuavaSchemaSourceCacheTest {
         }
 
         @Override
-        public InputStream openStream() {
-            return new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
+        public Reader openStream() {
+            return new StringReader(content);
         }
 
         @Override
index 4002d147ce70a2d04f197a70f8d4e28860a12def..604143db50285af2dcf861c3bc730a173aa8a4d8 100644 (file)
@@ -15,9 +15,8 @@ import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -109,8 +108,8 @@ public class SoftSchemaSourceCacheTest {
         }
 
         @Override
-        public InputStream openStream() {
-            return new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
+        public Reader openStream() {
+            return new StringReader(content);
         }
 
         @Override