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 static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects.ToStringHelper;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.nio.file.Files;
17 import java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.yangtools.concepts.Delegator;
22 * A {@link YinTextSchemaSource} backed by a file.
24 * @author Robert Varga
26 final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<File> {
27 private final @NonNull File file;
29 YinTextFileSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull File file) {
31 this.file = requireNonNull(file);
35 public File getDelegate() {
40 public InputStream openStream() throws IOException {
41 return Files.newInputStream(file.toPath());
45 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
46 return toStringHelper.add("file", file);
50 public Optional<String> getSymbolicName() {
51 return Optional.of(file.toString());