Switch to StandardCharsets 81/41981/2
authorRobert Varga <rovarga@cisco.com>
Mon, 18 Jul 2016 14:40:07 +0000 (16:40 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 18 Jul 2016 15:28:43 +0000 (17:28 +0200)
Guava's Charsets should not be used when StandardCharsets are
available.

Change-Id: I7c52bd3070bb48857cbba82e8d4bc5993d7aea9d
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/SpecificReferenceListMetadata.java
opendaylight/commons/protocol-framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java
opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/ModuleInfoBundleTracker.java
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java
opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java
opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/CapabilityStrippingConfigSnapshotHolderTest.java
opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlUtil.java

index 1aef1411290481fc2cbc5133d7def0642ea861ac..553b364d77ea09c78e4b3c5e9a7150ef12c402e9 100644 (file)
@@ -7,11 +7,11 @@
  */
 package org.opendaylight.controller.blueprint.ext;
 
  */
 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 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;
 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 {
         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);
                 int ci = line.indexOf('#');
                 if(ci >= 0) {
                     line = line.substring(0, ci);
index cb9e18085867b2687403e96f3a01d52cbcd90881..36bf4a1740021b64b4fb54fccf50feffcd8bef03 100644 (file)
@@ -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 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 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<Object> out) {
 /**
  *
  */
 public class SimpleByteToMessageDecoder extends ByteToMessageDecoder {
     @Override
     protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) {
-        out.add(new SimpleMessage(Charsets.UTF_8.decode(in.nioBuffer()).toString()));
+        out.add(new SimpleMessage(StandardCharsets.UTF_8.decode(in.nioBuffer()).toString()));
     }
 }
     }
 }
index 233545798fde3573dbd9169cf2c871da7259f64b..c819339afcb30dfec02727eeec77182eef6264ad 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.controller.config.facade.xml.osgi;
 
 
 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;
 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.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;
 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()) {
         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);
             }
         } catch (SchemaSourceException | IOException e) {
             LOG.warn("Unable to provide source for {}", moduleIdentifier, e);
index 15e62552152cb341e1467a6d14e2a25c168b9a9e..83d144d4aeae3adb4160c7bd86c0b2a1588cb8d0 100644 (file)
@@ -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 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 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;
 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<Boole
                 bundle, resource, event);
         if (resource != null) {
             try {
                 bundle, resource, event);
         if (resource != null) {
             try {
-                for (String factoryClassName : Resources.readLines(resource, Charsets.UTF_8)) {
+                for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
                     registerFactory(factoryClassName, bundle);
                 }
 
                     registerFactory(factoryClassName, bundle);
                 }
 
index e22fb4d919615becd5ed7d80c48396731be90622..7aa74ed18f146b18f02b9605aa59af657ca7e6d7 100644 (file)
@@ -8,13 +8,13 @@
 package org.opendaylight.controller.config.manager.impl.osgi.mapping;
 
 import static java.lang.String.format;
 package org.opendaylight.controller.config.manager.impl.osgi.mapping;
 
 import static java.lang.String.format;
-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 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 java.nio.charset.StandardCharsets;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
@@ -79,7 +79,7 @@ public final class ModuleInfoBundleTracker implements AutoCloseable,
         List<ObjectRegistration<YangModuleInfo>> registrations = new LinkedList<>();
 
         try {
         List<ObjectRegistration<YangModuleInfo>> 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));
                 LOG.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle);
                 YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle);
                 registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
index 6a6d360cfa794c2209ba7d5fe28a8dc1efeca3ab..68a33be5e67e02cf30f9fa83ca123fd82545ad76 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.controller.config.persist.storage.file.xml.model;
 
  */
 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 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;
 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 {
 
     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);
         }
         } catch (IOException e) {
             throw new IllegalStateException("Unexpected error reading file" + from, e);
         }
index dc1fc78a243a2af4658ce3cc180f82cdfe4de671..0b9e1b3a09b6c1628be5c608c570573c8ac5c5a5 100644 (file)
@@ -17,12 +17,12 @@ import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
 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 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;
 import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
@@ -47,7 +47,7 @@ public class FileStorageAdapterTest {
         if (!file.exists()) {
             return;
         }
         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();
     }
         i = 1;
         storage = new XmlFileStorageAdapter();
     }
@@ -105,7 +105,7 @@ public class FileStorageAdapterTest {
 
         storage.persistConfig(holder);
 
 
         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<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
         ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
         ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
@@ -152,7 +152,7 @@ public class FileStorageAdapterTest {
 
         storage.persistConfig(holder);
 
 
         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<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
 
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
@@ -184,7 +184,7 @@ public class FileStorageAdapterTest {
         storage.setFeaturesService(mock);
         storage.persistConfig(holder);
 
         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<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
 
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
@@ -212,7 +212,7 @@ public class FileStorageAdapterTest {
                 "         </configuration>\n" +
                 "      </snapshot>\n" +
                 "   </snapshots>\n" +
                 "         </configuration>\n" +
                 "      </snapshot>\n" +
                 "   </snapshots>\n" +
-                "</persisted-snapshots>", file, Charsets.UTF_8);
+                "</persisted-snapshots>", file, StandardCharsets.UTF_8);
 
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
 
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
@@ -241,7 +241,7 @@ public class FileStorageAdapterTest {
         storage.persistConfig(holder);
         storage.persistConfig(holder);
 
         storage.persistConfig(holder);
         storage.persistConfig(holder);
 
-        List<String> readLines = com.google.common.io.Files.readLines(file, Charsets.UTF_8);
+        List<String> readLines = com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8);
         assertEquals(29, readLines.size());
 
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(29, readLines.size());
 
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
index ad625bd463d55cbd13d190da30a55a218fa4c210..970805e1ef6cc030a27bbcea30b78ab502ed9e93 100644 (file)
@@ -9,10 +9,10 @@ package org.opendaylight.controller.config.persist.impl;
 
 import static org.junit.Assert.assertEquals;
 
 
 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 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;
 import java.util.HashSet;
 import java.util.Set;
 import org.junit.Test;
@@ -37,11 +37,11 @@ public class CapabilityStrippingConfigSnapshotHolderTest {
     }
 
     private Set<String> readLines(String fileName) throws IOException {
     }
 
     private Set<String> 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 {
     }
 
     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);
     }
 
 }
     }
 
 }
index 6f0b13c6a741e28f7714e64b6ed00da73a22bf9a..a69bab5cb133375a792c5320da5979eb151cb4a2 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.controller.config.util.xml;
 
 
 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;
 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.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;
 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 {
     }
 
     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
     }
 
     // TODO improve exceptions throwing