2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.InputStream;
15 import java.nio.file.Files;
16 import java.nio.file.Path;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.concepts.Delegator;
19 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
22 * A {@link YinTextSource} backed by a file.
24 final class YinTextFileSource extends YinTextSource implements Delegator<Path> {
25 private final @NonNull Path path;
27 YinTextFileSource(final @NonNull SourceIdentifier sourceId, final @NonNull Path path) {
29 this.path = requireNonNull(path);
33 public Path getDelegate() {
38 public InputStream openStream() throws IOException {
39 return Files.newInputStream(path);
43 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
44 return super.addToStringAttributes(toStringHelper).add("path", path);
48 public String symbolicName() {
49 return path.toString();