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
9 package org.opendaylight.yangtools.yang.parser.util;
11 import org.apache.commons.io.IOUtils;
13 import java.io.ByteArrayInputStream;
14 import java.io.IOException;
15 import java.io.InputStream;
17 public class NamedByteArrayInputStream extends ByteArrayInputStream implements NamedInputStream {
18 private final String toString;
19 private NamedByteArrayInputStream(byte[] buf, String toString) {
21 this.toString = toString;
24 public static ByteArrayInputStream create(InputStream originalIS) throws IOException {
25 String content = IOUtils.toString(originalIS);
26 if (originalIS instanceof NamedInputStream) {
27 return new NamedByteArrayInputStream(content.getBytes(), originalIS.toString());
29 return new ByteArrayInputStream(content.getBytes());
34 public String toString() {