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
8 package org.opendaylight.controller.netconf.impl.util;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.netconf.api.NetconfMessage;
12 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import org.w3c.dom.Document;
16 import org.xml.sax.SAXException;
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.IOException;
22 import java.io.InputStream;
24 public class NetconfUtil {
26 private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
28 public static NetconfMessage createMessage(final File f) {
29 Preconditions.checkNotNull(f, "File parameter was null");
31 return createMessage(new FileInputStream(f));
32 } catch (final FileNotFoundException e) {
33 logger.warn("File {} not found.", f, e);
38 public static NetconfMessage createMessage(final InputStream is) {
39 Preconditions.checkNotNull(is, "InputStream parameter was null");
42 doc = XmlUtil.readXmlToDocument(is);
43 } catch (final IOException e) {
44 logger.warn("Error ocurred while parsing stream.", e);
45 } catch (final SAXException e) {
46 logger.warn("Error ocurred while final parsing stream.", e);
48 return (doc == null) ? null : new NetconfMessage(doc);