2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Ericsson
4 * Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.input;
23 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
28 * Supplies input from a stream. Closing of the stream is responsibility of the client.
30 * @author Mark Hollmann
32 public class BufferedStreamYangInput extends ByteArrayYangInput {
34 public BufferedStreamYangInput(final String name, final InputStream inputStream) throws IOException {
35 this(name, inputStream, MEDIA_TYPE_YANG);
38 public BufferedStreamYangInput(final String name, final InputStream inputStream, final String mediaType)
40 super(getBytes(inputStream), name, mediaType);
43 private static byte[] getBytes(final InputStream inputStream) throws IOException {
44 final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
47 byte[] data = new byte[100000];
49 while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
50 buffer.write(data, 0, nRead);
53 return buffer.toByteArray();