kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject [kafka] branch trunk updated: HOTFIX: Simplify ConsoleConsumer stripWithPrefix function
Date Wed, 02 May 2018 20:32:20 GMT
This is an automated email from the ASF dual-hosted git repository.

guozhang pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new a7746dd  HOTFIX: Simplify ConsoleConsumer stripWithPrefix function
a7746dd is described below

commit a7746dd5b4d1eb529433b33be65aa2decd99a737
Author: Guozhang Wang <wangguoz@gmail.com>
AuthorDate: Wed May 2 13:32:05 2018 -0700

    HOTFIX: Simplify ConsoleConsumer stripWithPrefix function
---
 core/src/main/scala/kafka/tools/ConsoleConsumer.scala | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/core/src/main/scala/kafka/tools/ConsoleConsumer.scala b/core/src/main/scala/kafka/tools/ConsoleConsumer.scala
index 7675d92..befc16c 100755
--- a/core/src/main/scala/kafka/tools/ConsoleConsumer.scala
+++ b/core/src/main/scala/kafka/tools/ConsoleConsumer.scala
@@ -19,9 +19,8 @@ package kafka.tools
 
 import java.io.PrintStream
 import java.nio.charset.StandardCharsets
-import java.util
 import java.util.concurrent.CountDownLatch
-import java.util.{Locale, Map, Properties, Random}
+import java.util.{Locale, Properties, Random}
 
 import com.typesafe.scalalogging.LazyLogging
 import joptsimple._
@@ -536,25 +535,20 @@ class DefaultMessageFormatter extends MessageFormatter {
     // Note that `toString` will be called on the instance returned by `Deserializer.deserialize`
     if (props.containsKey("key.deserializer")) {
       keyDeserializer = Some(Class.forName(props.getProperty("key.deserializer")).newInstance().asInstanceOf[Deserializer[_]])
-      keyDeserializer.get.configure(JavaConversions.propertiesAsScalaMap(stripWithPrefix("key.deserializer.",
props)).asJava, true)
+      keyDeserializer.get.configure(JavaConversions.propertiesAsScalaMap(propertiesWithKeyPrefixStripped("key.deserializer.",
props)).asJava, true)
     }
     // Note that `toString` will be called on the instance returned by `Deserializer.deserialize`
     if (props.containsKey("value.deserializer")) {
       valueDeserializer = Some(Class.forName(props.getProperty("value.deserializer")).newInstance().asInstanceOf[Deserializer[_]])
-      valueDeserializer.get.configure(JavaConversions.propertiesAsScalaMap(stripWithPrefix("value.deserializer.",
props)).asJava, false)
+      valueDeserializer.get.configure(JavaConversions.propertiesAsScalaMap(propertiesWithKeyPrefixStripped("value.deserializer.",
props)).asJava, false)
     }
   }
 
-  def stripWithPrefix(prefix: String, props: Properties): Properties = {
+  private def propertiesWithKeyPrefixStripped(prefix: String, props: Properties): Properties
= {
     val newProps = new Properties()
     import scala.collection.JavaConversions._
-    for (entry <- props) {
-      val key: String = entry._1
-      val value: String = entry._2
-
-      if (key.startsWith(prefix) && key.length > prefix.length)
-        newProps.put(key.substring(prefix.length), value)
-    }
+    for ((key, value) <- props if key.startsWith(prefix) && key.length > prefix.length)
+      newProps.put(key.substring(prefix.length), value)
 
     newProps
   }

-- 
To stop receiving notification emails like this one, please contact
guozhang@apache.org.

Mime
View raw message