Make SerializationUtils#write variadic
This commit is contained in:
		@@ -3,6 +3,8 @@ package envoy.util;
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Defines utility methods related to serialization.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Project: <strong>envoy-client</strong><br>
 | 
			
		||||
 * File: <strong>SerializationUtils.java</strong><br>
 | 
			
		||||
 * Created: <strong>23.12.2019</strong><br>
 | 
			
		||||
@@ -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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user