From f7de07aca27c1edb8c652f5e60518ad391abda12 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 13 Jun 2020 18:32:24 +0200 Subject: [PATCH] Make SerializationUtils#write variadic --- src/main/java/envoy/util/SerializationUtils.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/envoy/util/SerializationUtils.java b/src/main/java/envoy/util/SerializationUtils.java index 68bd098..558429c 100644 --- a/src/main/java/envoy/util/SerializationUtils.java +++ b/src/main/java/envoy/util/SerializationUtils.java @@ -3,6 +3,8 @@ package envoy.util; import java.io.*; /** + * Defines utility methods related to serialization. + *

* Project: envoy-client
* File: SerializationUtils.java
* Created: 23.12.2019
@@ -92,22 +94,23 @@ public class SerializationUtils { } /** - * Serializes an arbitrary object to a file. + * Serializes arbitrary objects to a file. * * @param file the file to serialize to - * @param obj the object to serialize + * @param objs the objects to serialize * @throws IOException if an error occurred during serialization * @since Envoy Common v0.2-alpha */ - public static void write(File file, Object obj) throws IOException { + public static void write(File file, Object... objs) throws IOException { if (file == null) throw new NullPointerException("File is null"); - if (obj == null) throw new NullPointerException("Object to serialize is null"); + if (objs == null) throw new NullPointerException("Null array passed to serialize"); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file))) { - out.writeObject(obj); + for (var obj : objs) + out.writeObject(obj); } }