2 * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.config.yang.store.impl;
10 import static org.junit.Assert.assertNotNull;
12 import java.io.ByteArrayInputStream;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.util.ArrayList;
16 import java.util.Collection;
18 import org.apache.commons.io.IOUtils;
19 import org.opendaylight.controller.config.yang.store.api.YangStoreException;
20 import org.opendaylight.controller.config.yang.store.api.YangStoreService;
21 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
23 public class HardcodedYangStoreService implements YangStoreService {
25 private final Collection<ByteArrayInputStream> byteArrayInputStreams;
27 public HardcodedYangStoreService(
28 Collection<? extends InputStream> inputStreams)
29 throws YangStoreException, IOException {
30 byteArrayInputStreams = new ArrayList<>();
31 for (InputStream inputStream : inputStreams) {
32 assertNotNull(inputStream);
33 byte[] content = IOUtils.toByteArray(inputStream);
34 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
36 byteArrayInputStreams.add(byteArrayInputStream);
41 public YangStoreSnapshot getYangStoreSnapshot() throws YangStoreException {
42 for (InputStream inputStream : byteArrayInputStreams) {
45 } catch (IOException e) {
46 throw new RuntimeException(e);
49 return new MbeParser().parseYangFiles(byteArrayInputStreams);