@Override
@Deprecated
public Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams) {
- Collection<ByteSource> sources = ParserUtils.streamsToByteSources(yangModelStreams);
try {
+ Collection<ByteSource> sources = ParserUtils.streamsToByteSources(yangModelStreams);
return parseSources(sources).getModules();
} catch (IOException | YangSyntaxErrorException e) {
throw new YangParseException("Failed to parse yang data", e);
@Override
@Deprecated
public Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams, final SchemaContext context) {
- Collection<ByteSource> sources = ParserUtils.streamsToByteSources(yangModelStreams);
try {
+ Collection<ByteSource> sources = ParserUtils.streamsToByteSources(yangModelStreams);
return parseSources(sources, context).getModules();
} catch (IOException | YangSyntaxErrorException e) {
throw new YangParseException("Failed to parse yang data", e);
sourceToBuilder.put(source, moduleBuilder);
}
+ ParserUtils.setSourceToBuilder(sourceToBuilder);
return sourceToBuilder;
}
package org.opendaylight.yangtools.yang.parser.util;
-import org.apache.commons.io.IOUtils;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.commons.io.IOUtils;
public class NamedByteArrayInputStream extends ByteArrayInputStream implements NamedInputStream {
private final String toString;
- private NamedByteArrayInputStream(byte[] buf, String toString) {
+ public NamedByteArrayInputStream(byte[] buf, String toString) {
super(buf);
this.toString = toString;
}
*/
package org.opendaylight.yangtools.yang.parser.util;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
private ParserUtils() {
}
- public static Collection<ByteSource> streamsToByteSources(final Collection<InputStream> streams) {
- return Collections2.transform(streams, new Function<InputStream, ByteSource>() {
- @Override
- public ByteSource apply(final InputStream input) {
- return new ByteSource() {
- @Override
- public InputStream openStream() throws IOException {
- return NamedByteArrayInputStream.create(input);
- }
- };
- }
- });
+ public static Collection<ByteSource> streamsToByteSources(final Collection<InputStream> streams) throws IOException {
+ Collection<ByteSource> result = new HashSet<>();
+ for (InputStream stream : streams) {
+ result.add(new ByteSourceImpl(stream));
+ }
+ return result;
}
public static ByteSource fileToByteSource(final File file) {
return result;
}
+ private static final class ByteSourceImpl extends ByteSource {
+ private final String toString;
+ private final ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+ private ByteSourceImpl(InputStream input) throws IOException {
+ toString = input.toString();
+ IOUtils.copy(input, output);
+ }
+
+ @Override
+ public InputStream openStream() throws IOException {
+ return new NamedByteArrayInputStream(output.toByteArray(), toString);
+ }
+ }
+
}