Fix sonar warnings
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / repo / ResourceYangSource.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.yangtools.yang.parser.repo;
10
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
16
17 final class ResourceYangSource extends YangTextSchemaSource {
18
19     private final String resourceName;
20
21     ResourceYangSource(final String resourceName) {
22         super(identifierFromFilename(resourceName));
23         this.resourceName = resourceName;
24     }
25
26     @Override
27     protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
28         return toStringHelper.add("resource", resourceName);
29     }
30
31     @Override
32     public InputStream openStream() throws IOException {
33         return Preconditions.checkNotNull(getClass().getResourceAsStream(resourceName));
34     }
35 }