diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java index 3a9658ea816..206dd262ed8 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java @@ -44,30 +44,14 @@ public class PluginsAndModules implements Writeable, ToXContent { } public PluginsAndModules(StreamInput in) throws IOException { - int pluginsSize = in.readInt(); - List plugins = new ArrayList<>(pluginsSize); - for (int i = 0; i < pluginsSize; i++) { - plugins.add(new PluginInfo(in)); - } - this.plugins = Collections.unmodifiableList(plugins); - int modulesSize = in.readInt(); - List modules = new ArrayList<>(modulesSize); - for (int i = 0; i < modulesSize; i++) { - modules.add(new PluginInfo(in)); - } - this.modules = Collections.unmodifiableList(modules); + this.plugins = Collections.unmodifiableList(in.readList(PluginInfo::new)); + this.modules = Collections.unmodifiableList(in.readList(PluginInfo::new)); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeInt(plugins.size()); - for (PluginInfo plugin : getPluginInfos()) { - plugin.writeTo(out); - } - out.writeInt(modules.size()); - for (PluginInfo module : getModuleInfos()) { - module.writeTo(out); - } + out.writeList(plugins); + out.writeList(modules); } /** diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java index d370a06cdc8..ca0bb4f3e80 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java @@ -36,7 +36,6 @@ import java.lang.management.PlatformManagedObject; import java.lang.management.RuntimeMXBean; import java.lang.reflect.Method; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -226,11 +225,7 @@ public class JvmInfo implements Writeable, ToXContent { } bootClassPath = in.readString(); classPath = in.readString(); - systemProperties = new HashMap<>(); - int size = in.readInt(); - for (int i = 0; i < size; i++) { - systemProperties.put(in.readString(), in.readString()); - } + systemProperties = in.readMap(StreamInput::readString, StreamInput::readString); mem = new Mem(in); gcCollectors = in.readStringArray(); memoryPools = in.readStringArray(); @@ -257,7 +252,7 @@ public class JvmInfo implements Writeable, ToXContent { } out.writeString(bootClassPath); out.writeString(classPath); - out.writeInt(systemProperties.size()); + out.writeVInt(this.systemProperties.size()); for (Map.Entry entry : systemProperties.entrySet()) { out.writeString(entry.getKey()); out.writeString(entry.getValue()); diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java index d30d872691c..70c0f2c9598 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -40,20 +39,12 @@ public class ThreadPoolInfo implements Writeable, Iterable, ToX } public ThreadPoolInfo(StreamInput in) throws IOException { - int size = in.readVInt(); - List infos = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - infos.add(new ThreadPool.Info(in)); - } - this.infos = Collections.unmodifiableList(infos); + this.infos = Collections.unmodifiableList(in.readList(ThreadPool.Info::new)); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeVInt(infos.size()); - for (ThreadPool.Info info : infos) { - info.writeTo(out); - } + out.writeList(infos); } @Override