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}.
25 * export the data to this stream
27 public Exporter(OutputStream out
) {
29 throw new NullPointerException(
30 "Cannot create an be.nikiroo.utils.serials.Exporter that will export to NULL");
34 map
= new HashMap
<Integer
, Object
>();
38 * Serialise the given object and add it to the list.
40 * <b>Important: </b>If the operation fails (with a
41 * {@link NotSerializableException}), the {@link Exporter} will be corrupted
42 * (will contain bad, most probably not importable data).
45 * the object to serialise
46 * @return this (for easier appending of multiple values)
48 * @throws NotSerializableException
49 * if the object cannot be serialised (in this case, the
50 * {@link Exporter} can contain bad, most probably not
53 * in case of I/O error
55 public Exporter
append(Object o
) throws NotSerializableException
,
57 SerialUtils
.append(out
, o
, map
);