HOTFIX: Simplify ConsoleConsumer stripWithPrefix function
@@ -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)
+ for ((key, value) <- props if key.startsWith(prefix) && key.length > prefix.length)
newProps.put(key.substring(prefix.length), value)
- }
newProps
}
