a5d15e8cead9d9916ac71e349aecb0b1925ea863
[yangtools.git] / yang / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / YangSourceFromFile.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.yang2sources.plugin;
9
10 import com.google.common.base.Preconditions;
11 import java.io.File;
12 import java.io.IOException;
13 import java.io.InputStream;
14 import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
15
16 class YangSourceFromFile extends YangSourceFromDependency {
17
18     private final File source;
19
20     public YangSourceFromFile(File source) {
21         this.source = Preconditions.checkNotNull(source);
22     }
23
24     @Override
25     public InputStream openStream() throws IOException {
26
27         return new NamedFileInputStream(source, YangToSourcesProcessor.META_INF_YANG_STRING + File.separator
28                 + source.getName());
29     }
30
31     @Override
32     public long size() throws IOException {
33         return source.length();
34     }
35
36 }