From d95368f629eb95d9e620d6394d445b689ad7bd11 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 3 May 2023 03:04:35 +0200 Subject: [PATCH] YangTextSchemaSource is a CharSource 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 --- .../repo/YangTextSchemaContextResolver.java | 2 +- .../repo/YangStatementStreamSource.java | 10 +- .../util/LiteralYangTextSchemaSource.java | 9 +- .../plugin/ProcessorModuleReactor.java | 3 +- .../plugin/ScannedDependency.java | 5 +- .../plugin/YangToSourcesProcessor.java | 6 +- .../api/DelegatedYangTextSchemaSource.java | 14 +-- .../api/ResourceYangTextSchemaSource.java | 12 ++- ...e.java => StringYangTextSchemaSource.java} | 22 +++-- .../repo/api/YangTextFileSchemaSource.java | 12 ++- .../model/repo/api/YangTextSchemaSource.java | 91 +++++++++++++++++-- .../repo/fs/FilesystemSchemaSourceCache.java | 4 +- ...ystemSchemaSourceCacheIntegrationTest.java | 8 +- .../fs/FilesystemSchemaSourceCacheTest.java | 9 +- .../repo/spi/GuavaSchemaSourceCacheTest.java | 9 +- .../repo/spi/SoftSchemaSourceCacheTest.java | 9 +- 16 files changed, 155 insertions(+), 70 deletions(-) rename yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/{ImmediateYangTextSchemaSource.java => StringYangTextSchemaSource.java} (60%) diff --git a/parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java b/parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java index bb6e4d40e3..8e087bf256 100644 --- a/parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java +++ b/parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java @@ -134,7 +134,7 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem } } - text = YangTextSchemaSource.delegateForByteSource(parsedId, source); + text = YangTextSchemaSource.delegateForCharSource(parsedId, source); } else { text = source; } diff --git a/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangStatementStreamSource.java b/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangStatementStreamSource.java index 3b74853103..cfabdfbfb2 100644 --- a/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangStatementStreamSource.java +++ b/parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangStatementStreamSource.java @@ -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(); diff --git a/parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSchemaSource.java b/parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSchemaSource.java index 43347516b3..aa50efb232 100644 --- a/parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSchemaSource.java +++ b/parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSchemaSource.java @@ -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 diff --git a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java index 01e06e454e..177bd4bfb6 100644 --- a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java +++ b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java @@ -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); } diff --git a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ScannedDependency.java b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ScannedDependency.java index d86df7d114..3bd4b2b015 100644 --- a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ScannedDependency.java +++ b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ScannedDependency.java @@ -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)); } } diff --git a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java index 99685df218..1ed6f6888f 100644 --- a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java +++ b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java @@ -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.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); diff --git a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYangTextSchemaSource.java b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYangTextSchemaSource.java index 26e5bc7221..65a7e038ac 100644 --- a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYangTextSchemaSource.java +++ b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYangTextSchemaSource.java @@ -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 { - private final @NonNull ByteSource delegate; +final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator { + 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(); } diff --git a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java index 7eef2ff028..c0cf6ec2fb 100644 --- a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java +++ b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java @@ -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 { 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 diff --git a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ImmediateYangTextSchemaSource.java b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/StringYangTextSchemaSource.java similarity index 60% rename from yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ImmediateYangTextSchemaSource.java rename to yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/StringYangTextSchemaSource.java index c3f5f2a73f..9ac1d59c53 100644 --- a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ImmediateYangTextSchemaSource.java +++ b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/StringYangTextSchemaSource.java @@ -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); } } diff --git a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextFileSchemaSource.java b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextFileSchemaSource.java index 6821e1a016..c17d96bd92 100644 --- a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextFileSchemaSource.java +++ b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextFileSchemaSource.java @@ -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 { 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 diff --git a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java index 1300faeb71..ec5a93ff9f 100644 --- a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java +++ b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java @@ -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; diff --git a/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java b/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java index ddc0b090e9..6871381fcb 100644 --- a/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java +++ b/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java @@ -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