2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.spi.source;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import java.io.IOException;
14 import java.io.InputStreamReader;
15 import java.io.Reader;
17 import java.nio.charset.Charset;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.yangtools.concepts.Delegator;
20 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
23 * A resource-backed {@link YangTextSource}.
25 final class ResourceYangTextSource extends YangTextSource implements Delegator<URL> {
26 private final @NonNull URL url;
27 private final @NonNull Charset charset;
29 ResourceYangTextSource(final SourceIdentifier sourceId, final URL url, final Charset charset) {
31 this.url = requireNonNull(url);
32 this.charset = requireNonNull(charset);
36 public URL getDelegate() {
41 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
42 return super.addToStringAttributes(toStringHelper).add("url", url);
46 public Reader openStream() throws IOException {
47 return new InputStreamReader(url.openStream(), charset);
51 public String symbolicName() {
52 return url.toString();