Cleanup use of Guava library
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / YangTextFileSchemaSource.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.repo.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.nio.file.Files;
17 import java.util.Optional;
18 import org.opendaylight.yangtools.concepts.Delegator;
19
20 /**
21  * A {@link YangTextSchemaSource} backed by a file.
22  *
23  * @author Robert Varga
24  */
25 final class YangTextFileSchemaSource extends YangTextSchemaSource implements Delegator<File> {
26     private final File file;
27
28     YangTextFileSchemaSource(final SourceIdentifier identifier, final File file) {
29         super(identifier);
30         this.file = requireNonNull(file);
31     }
32
33     @Override
34     public File getDelegate() {
35         return file;
36     }
37
38     @Override
39     public InputStream openStream() throws IOException {
40         return Files.newInputStream(file.toPath());
41     }
42
43     @Override
44     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
45         return toStringHelper.add("file", file);
46     }
47
48     @Override
49     public Optional<String> getSymbolicName() {
50         return Optional.of(file.toString());
51     }
52 }