package org.opendaylight.controller.netconf.util.test;
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.ByteSource;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-
import javax.xml.parsers.ParserConfigurationException;
-
+import org.opendaylight.controller.config.util.xml.XmlUtil;
import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
-import com.google.common.base.Charsets;
-import com.google.common.base.Preconditions;
-import com.google.common.io.CharStreams;
-import com.google.common.io.InputSupplier;
-
public class XmlFileLoader {
public static NetconfMessage xmlFileToNetconfMessage(final String fileName) throws IOException, SAXException,
public static Document xmlFileToDocument(final String fileName) throws IOException, SAXException,
ParserConfigurationException {
try (InputStream resourceAsStream = XmlFileLoader.class.getClassLoader().getResourceAsStream(fileName)) {
- Preconditions.checkNotNull(resourceAsStream);
+ Preconditions.checkNotNull(resourceAsStream, fileName);
final Document doc = XmlUtil.readXmlToDocument(resourceAsStream);
return doc;
}
public static String fileToString(final String fileName) throws IOException {
try (InputStream resourceAsStream = XmlFileLoader.class.getClassLoader().getResourceAsStream(fileName)) {
Preconditions.checkNotNull(resourceAsStream);
-
- InputSupplier<? extends InputStream> supplier = new InputSupplier<InputStream>() {
+ return new ByteSource() {
@Override
- public InputStream getInput() throws IOException {
+ public InputStream openStream() {
return resourceAsStream;
}
- };
-
- InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(supplier, Charsets.UTF_8);
+ }.asCharSource(Charsets.UTF_8).read();
- return CharStreams.toString(readerSupplier);
}
}