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 1aef141..553b364 100644 (file)
@@ -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);
index cb9e180..36bf4a1 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 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<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 2335457..c819339 100644 (file)
@@ -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);
index 15e6255..83d144d 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 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<Boole
                 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);
                 }
 
index e22fb4d..7aa74ed 100644 (file)
@@ -8,13 +8,13 @@
 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 java.nio.charset.StandardCharsets;
 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 {
-            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));
index 6a6d360..68a33be 100644 (file)
@@ -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);
         }
index dc1fc78..0b9e1b3 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 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<ConfigSnapshotHolder> 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<ConfigSnapshotHolder> 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<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());
@@ -212,7 +212,7 @@ public class FileStorageAdapterTest {
                 "         </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());
@@ -241,7 +241,7 @@ public class FileStorageAdapterTest {
         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();
index ad625bd..970805e 100644 (file)
@@ -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<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 {
-        return Resources.toString(getClass().getResource(fileName), Charsets.UTF_8);
+        return Resources.toString(getClass().getResource(fileName), StandardCharsets.UTF_8);
     }
 
 }
index 6f0b13c..a69bab5 100644 (file)
@@ -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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.