Replaces uses of IOUtils methods with guava/JDK equivalents.
Change-Id: I16ece0feec2f4dc84c3be91ec675a0294cffcffb
Signed-off-by: Robert Varga <rovarga@cisco.com>
<artifactId>guava</artifactId>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
-
<!--Dependencies regardign RuntimeGeneratedMappingService-->
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
package org.opendaylight.controller.config.manager.impl.osgi;
import static java.lang.String.format;
-
import com.google.common.annotations.VisibleForTesting;
-import java.io.InputStream;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import java.io.IOException;
import java.net.URL;
-import java.util.List;
-import org.apache.commons.io.IOUtils;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* OSGi extender that listens for bundle activation events. Reads file
* META-INF/services/org.opendaylight.controller.config.spi.ModuleFactory, each
LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}",
bundle, resource, event);
if (resource != null) {
- try (InputStream inputStream = resource.openStream()) {
- List<String> lines = IOUtils.readLines(inputStream);
- for (String factoryClassName : lines) {
+ try {
+ for (String factoryClassName : Resources.readLines(resource, Charsets.UTF_8)) {
registerFactory(factoryClassName, bundle);
}
- } catch (Exception e) {
+ } catch (IOException e) {
LOG.error("Error while reading {}", resource, e);
throw new RuntimeException(e);
}
package org.opendaylight.controller.config.manager.impl.osgi.mapping;
import static java.lang.String.format;
-
-import java.io.InputStream;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import org.apache.commons.io.IOUtils;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
}
List<ObjectRegistration<YangModuleInfo>> registrations = new LinkedList<>();
- try (InputStream inputStream = resource.openStream()) {
- List<String> lines = IOUtils.readLines(inputStream);
- for (String moduleInfoName : lines) {
+ try {
+ for (String moduleInfoName : Resources.readLines(resource, Charsets.UTF_8)) {
LOG.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle);
YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle);
registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
}
-
- } catch (Exception e) {
+ } catch (IOException e) {
LOG.error("Error while reading {}", resource, e);
throw new RuntimeException(e);
}
+
LOG.trace("Got following registrations {}", registrations);
return registrations;
}
import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_SCHEMA_QNAME;
import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DATA_QNAME;
import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
-
+import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.transform.dom.DOMSource;
-import org.apache.commons.io.IOUtils;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil;
@Override
public InputStream openStream() throws IOException {
- return IOUtils.toInputStream(schemaString.get());
+ return new ByteArrayInputStream(schemaString.get().getBytes(Charsets.UTF_8));
}
}
}
<type>test-jar</type>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>config-persister-directory-xml-adapter</artifactId>
package org.opendaylight.controller.netconf.persist.impl;
import static org.junit.Assert.assertEquals;
-
+import com.google.common.base.Charsets;
import com.google.common.collect.Sets;
+import com.google.common.io.Resources;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.w3c.dom.Element;
}
private Set<String> readLines(String fileName) throws IOException {
- return new HashSet<>(IOUtils.readLines(getClass().getResourceAsStream(fileName)));
+ return new HashSet<>(Resources.readLines(getClass().getResource(fileName), Charsets.UTF_8));
}
private String readToString(String fileName) throws IOException {
- return IOUtils.toString(getClass().getResourceAsStream(fileName));
+ return Resources.toString(getClass().getResource(fileName), Charsets.UTF_8);
}
}
<type>test-jar</type>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>xmlunit</groupId>
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import com.google.common.io.ByteStreams;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
}
LOG.info(sb.toString());
- outToServer.write(IOUtils.toByteArray(clientHello));
+ outToServer.write(ByteStreams.toByteArray(clientHello));
outToServer.write("]]>]]>".getBytes());
outToServer.flush();
// Thread.sleep(100);
- outToServer.write(IOUtils.toByteArray(getConfig));
+ outToServer.write(ByteStreams.toByteArray(getConfig));
outToServer.write("]]>]]>".getBytes());
outToServer.flush();
Thread.sleep(100);
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
-
+import com.google.common.io.ByteStreams;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Before;
import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
assertNotNull(inputStream);
final byte[] content;
try {
- content = IOUtils.toByteArray(inputStream);
+ content = ByteStreams.toByteArray(inputStream);
} catch (IOException e) {
throw new IllegalStateException("Cannot read " + inputStream, e);
}
<groupId>${project.groupId}</groupId>
<artifactId>netconf-util</artifactId>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>