1 package be
.nikiroo
.utils
.serial
;
3 import java
.io
.IOException
;
4 import java
.io
.NotSerializableException
;
5 import java
.io
.OutputStream
;
6 import java
.util
.HashMap
;
10 * A simple class to serialise objects to {@link String}.
12 * This class does not support inner classes (it does support nested classes,
17 public class Exporter
{
18 private Map
<Integer
, Object
> map
;
19 private OutputStream out
;
22 * Create a new {@link Exporter}.
24 public Exporter(OutputStream out
) {
26 throw new NullPointerException(
27 "Cannot create an be.nikiroo.utils.serials.Exporter that will export to NULL");
31 map
= new HashMap
<Integer
, Object
>();
35 * Serialise the given object and add it to the list.
37 * <b>Important: </b>If the operation fails (with a
38 * {@link NotSerializableException}), the {@link Exporter} will be corrupted
39 * (will contain bad, most probably not importable data).
42 * the object to serialise
43 * @return this (for easier appending of multiple values)
45 * @throws NotSerializableException
46 * if the object cannot be serialised (in this case, the
47 * {@link Exporter} can contain bad, most probably not
50 * in case of I/O error
52 public Exporter
append(Object o
) throws NotSerializableException
,
54 SerialUtils
.append(out
, o
, map
);