1 package org.opendaylight.controller.netconf.impl.util;
3 import com.google.common.base.Preconditions;
4 import org.opendaylight.controller.netconf.api.NetconfMessage;
5 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8 import org.w3c.dom.Document;
9 import org.xml.sax.SAXException;
12 import java.io.FileInputStream;
13 import java.io.FileNotFoundException;
14 import java.io.IOException;
15 import java.io.InputStream;
17 public class NetconfUtil {
19 private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
21 public static NetconfMessage createMessage(final File f) {
22 Preconditions.checkNotNull(f, "File parameter was null");
24 return createMessage(new FileInputStream(f));
25 } catch (final FileNotFoundException e) {
26 logger.warn("File {} not found.", f, e);
31 public static NetconfMessage createMessage(final InputStream is) {
32 Preconditions.checkNotNull(is, "InputStream parameter was null");
35 doc = XmlUtil.readXmlToDocument(is);
36 } catch (final IOException e) {
37 logger.warn("Error ocurred while parsing stream.", e);
38 } catch (final SAXException e) {
39 logger.warn("Error ocurred while final parsing stream.", e);
41 return (doc == null) ? null : new NetconfMessage(doc);