86bcee75b48314ba6b30273cad5493d9de2a6116
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / DelegatedYangTextSchemaSource.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 com.google.common.base.MoreObjects.ToStringHelper;
11 import com.google.common.base.Preconditions;
12 import com.google.common.io.ByteSource;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import org.opendaylight.yangtools.concepts.Delegator;
16
17 final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator<ByteSource> {
18     private final ByteSource delegate;
19
20     DelegatedYangTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
21         super(identifier);
22         this.delegate = Preconditions.checkNotNull(delegate);
23     }
24
25     @Override
26     public ByteSource getDelegate() {
27         return delegate;
28     }
29
30     @Override
31     public InputStream openStream() throws IOException {
32         return delegate.openStream();
33     }
34
35     @Override
36     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
37         return toStringHelper.add("delegate", delegate);
38     }
39 }