From: Robert Varga Date: Mon, 18 Jul 2016 14:40:07 +0000 (+0200) Subject: Switch to StandardCharsets X-Git-Tag: release/boron~62 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=3fbfbc2881e4f18fd5972ec01c53c2a2d21aece1 Switch to StandardCharsets Guava's Charsets should not be used when StandardCharsets are available. Change-Id: I7c52bd3070bb48857cbba82e8d4bc5993d7aea9d Signed-off-by: Robert Varga --- diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/SpecificReferenceListMetadata.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/SpecificReferenceListMetadata.java index 1aef141129..553b364d77 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/SpecificReferenceListMetadata.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/SpecificReferenceListMetadata.java @@ -7,11 +7,11 @@ */ package org.opendaylight.controller.blueprint.ext; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.common.io.Resources; import java.io.IOException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -118,7 +118,7 @@ class SpecificReferenceListMetadata extends AbstractDependentComponentFactoryMet LOG.debug("{}: Found {} resource in bundle {}", logName(), resource, bundle.getSymbolicName()); try { - for(String line : Resources.readLines(resource, Charsets.UTF_8)) { + for(String line : Resources.readLines(resource, StandardCharsets.UTF_8)) { int ci = line.indexOf('#'); if(ci >= 0) { line = line.substring(0, ci); diff --git a/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java index cb9e180858..36bf4a1740 100644 --- a/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java +++ b/opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java @@ -10,17 +10,15 @@ package org.opendaylight.protocol.framework; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; - +import java.nio.charset.StandardCharsets; import java.util.List; -import com.google.common.base.Charsets; - /** * */ public class SimpleByteToMessageDecoder extends ByteToMessageDecoder { @Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List out) { - out.add(new SimpleMessage(Charsets.UTF_8.decode(in.nioBuffer()).toString())); + out.add(new SimpleMessage(StandardCharsets.UTF_8.decode(in.nioBuffer()).toString())); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java index 233545798f..c819339afc 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.config.facade.xml.osgi; -import com.google.common.base.Charsets; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.BiMap; @@ -19,6 +18,7 @@ import com.google.common.util.concurrent.CheckedFuture; import java.io.IOException; import java.io.InputStream; import java.lang.ref.SoftReference; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -157,7 +157,7 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver { try { final YangTextSchemaSource yangTextSchemaSource = source.checkedGet(); try(InputStream inStream = yangTextSchemaSource.openStream()) { - return new String(ByteStreams.toByteArray(inStream), Charsets.UTF_8); + return new String(ByteStreams.toByteArray(inStream), StandardCharsets.UTF_8); } } catch (SchemaSourceException | IOException e) { LOG.warn("Unable to provide source for {}", moduleIdentifier, e); diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java index 15e6255215..83d144d4ae 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java @@ -9,10 +9,10 @@ package org.opendaylight.controller.config.manager.impl.osgi; import static java.lang.String.format; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; import com.google.common.io.Resources; import java.io.IOException; import java.net.URL; +import java.nio.charset.StandardCharsets; import org.opendaylight.controller.config.spi.ModuleFactory; import org.osgi.framework.Bundle; import org.osgi.framework.BundleEvent; @@ -45,7 +45,7 @@ public class ModuleFactoryBundleTracker implements BundleTrackerCustomizer> registrations = new LinkedList<>(); try { - for (String moduleInfoName : Resources.readLines(resource, Charsets.UTF_8)) { + for (String moduleInfoName : Resources.readLines(resource, StandardCharsets.UTF_8)) { LOG.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle); YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle); registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo)); diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java index 6a6d360cfa..68a33be5e6 100644 --- a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java +++ b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java @@ -7,13 +7,13 @@ */ package org.opendaylight.controller.config.persist.storage.file.xml.model; -import com.google.common.base.Charsets; import com.google.common.base.Optional; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.io.Files; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -92,7 +92,7 @@ public final class Config { private static boolean isBlank(File from) { try { - return StringUtils.isBlank(Files.toString(from, Charsets.UTF_8)); + return StringUtils.isBlank(Files.toString(from, StandardCharsets.UTF_8)); } catch (IOException e) { throw new IllegalStateException("Unexpected error reading file" + from, e); } diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java b/opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java index dc1fc78a24..0b9e1b3a09 100644 --- a/opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java +++ b/opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java @@ -17,12 +17,12 @@ import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import com.google.common.base.Charsets; import com.google.common.collect.Sets; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; @@ -47,7 +47,7 @@ public class FileStorageAdapterTest { if (!file.exists()) { return; } - com.google.common.io.Files.write("", file, Charsets.UTF_8); + com.google.common.io.Files.write("", file, StandardCharsets.UTF_8); i = 1; storage = new XmlFileStorageAdapter(); } @@ -105,7 +105,7 @@ public class FileStorageAdapterTest { storage.persistConfig(holder); - assertEquals(29, com.google.common.io.Files.readLines(file, Charsets.UTF_8).size()); + assertEquals(29, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size()); List lastConf = storage.loadLastConfigs(); assertEquals(1, lastConf.size()); ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0); @@ -152,7 +152,7 @@ public class FileStorageAdapterTest { storage.persistConfig(holder); - assertEquals(29, com.google.common.io.Files.readLines(file, Charsets.UTF_8).size()); + assertEquals(29, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size()); List lastConf = storage.loadLastConfigs(); assertEquals(1, lastConf.size()); @@ -184,7 +184,7 @@ public class FileStorageAdapterTest { storage.setFeaturesService(mock); storage.persistConfig(holder); - assertEquals(20, com.google.common.io.Files.readLines(file, Charsets.UTF_8).size()); + assertEquals(20, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size()); List lastConf = storage.loadLastConfigs(); assertEquals(1, lastConf.size()); @@ -212,7 +212,7 @@ public class FileStorageAdapterTest { " \n" + " \n" + " \n" + - "", file, Charsets.UTF_8); + "", file, StandardCharsets.UTF_8); List lastConf = storage.loadLastConfigs(); assertEquals(1, lastConf.size()); @@ -241,7 +241,7 @@ public class FileStorageAdapterTest { storage.persistConfig(holder); storage.persistConfig(holder); - List readLines = com.google.common.io.Files.readLines(file, Charsets.UTF_8); + List readLines = com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8); assertEquals(29, readLines.size()); List lastConf = storage.loadLastConfigs(); diff --git a/opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java b/opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java index ad625bd463..970805e1ef 100644 --- a/opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java +++ b/opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java @@ -9,10 +9,10 @@ package org.opendaylight.controller.config.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.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; import org.junit.Test; @@ -37,11 +37,11 @@ public class CapabilityStrippingConfigSnapshotHolderTest { } private Set readLines(String fileName) throws IOException { - return new HashSet<>(Resources.readLines(getClass().getResource(fileName), Charsets.UTF_8)); + return new HashSet<>(Resources.readLines(getClass().getResource(fileName), StandardCharsets.UTF_8)); } private String readToString(String fileName) throws IOException { - return Resources.toString(getClass().getResource(fileName), Charsets.UTF_8); + return Resources.toString(getClass().getResource(fileName), StandardCharsets.UTF_8); } } diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlUtil.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlUtil.java index 6f0b13c6a7..a69bab5cb1 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlUtil.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlUtil.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.config.util.xml; -import com.google.common.base.Charsets; import com.google.common.base.Optional; import java.io.ByteArrayInputStream; import java.io.File; @@ -16,6 +15,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilder; @@ -98,7 +98,7 @@ public final class XmlUtil { } public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException { - return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(Charsets.UTF_8))); + return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8))); } // TODO improve exceptions throwing