Fix star import and enable checkstyle rule to prevent it.
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / util / NetconfUtil.java
1 package org.opendaylight.controller.netconf.impl.util;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.io.InputStream;
8
9 import org.opendaylight.controller.netconf.api.NetconfMessage;
10 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import org.w3c.dom.Document;
14 import org.xml.sax.SAXException;
15
16 // TODO purge nulls
17 public class NetconfUtil {
18
19     private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
20
21     public static NetconfMessage createMessage(final File f) {
22         try {
23             return createMessage(new FileInputStream(f));
24         } catch (final FileNotFoundException e) {
25             logger.warn("File {} not found.", f, e);
26         }
27         return null;
28     }
29
30     public static NetconfMessage createMessage(final InputStream is) {
31         Document doc = null;
32         try {
33             doc = XmlUtil.readXmlToDocument(is);
34         } catch (final IOException e) {
35             logger.warn("Error ocurred while parsing stream.", e);
36         } catch (final SAXException e) {
37             logger.warn("Error ocurred while final parsing stream.", e);
38         }
39         return (doc == null) ? null : new NetconfMessage(doc);
40     }
41 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.