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.repo.api;
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import com.google.common.base.Preconditions;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.nio.file.Files;
16 import java.util.Optional;
17 import org.opendaylight.yangtools.concepts.Delegator;
20 * A {@link YinTextSchemaSource} backed by a file.
22 * @author Robert Varga
24 final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<File> {
25 private final File file;
27 YinTextFileSchemaSource(final SourceIdentifier identifier, final File file) {
29 this.file = Preconditions.checkNotNull(file);
33 public File getDelegate() {
38 public InputStream openStream() throws IOException {
39 return Files.newInputStream(file.toPath());
43 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
44 return toStringHelper.add("file", file);
48 public Optional<String> getSymbolicName() {
49 return Optional.of(file.toString());