it now compiles
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / Exporter.java
CommitLineData
db31c358
NR
1package be.nikiroo.utils.serial;
2
a359464f 3import java.io.IOException;
db31c358 4import java.io.NotSerializableException;
143a64f4 5import java.io.OutputStream;
db31c358
NR
6import java.util.HashMap;
7import java.util.Map;
8
db31c358
NR
9/**
10 * A simple class to serialise objects to {@link String}.
11 * <p>
12 * This class does not support inner classes (it does support nested classes,
13 * though).
14 *
15 * @author niki
16 */
17public class Exporter {
18 private Map<Integer, Object> map;
143a64f4 19 private OutputStream out;
db31c358 20
f157aed8
NR
21 /**
22 * Create a new {@link Exporter}.
23 */
143a64f4
NR
24 public Exporter(OutputStream out) {
25 if (out == null) {
26 throw new NullPointerException(
27 "Cannot create an be.nikiroo.utils.serials.Exporter that will export to NULL");
28 }
29
30 this.out = out;
db31c358 31 map = new HashMap<Integer, Object>();
db31c358
NR
32 }
33
f157aed8
NR
34 /**
35 * Serialise the given object and add it to the list.
36 * <p>
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).
40 *
41 * @param o
42 * the object to serialise
43 * @return this (for easier appending of multiple values)
44 *
45 * @throws NotSerializableException
46 * if the object cannot be serialised (in this case, the
47 * {@link Exporter} can contain bad, most probably not
48 * importable data)
143a64f4
NR
49 * @throws IOException
50 * in case of I/O error
f157aed8 51 */
143a64f4
NR
52 public Exporter append(Object o) throws NotSerializableException,
53 IOException {
54 SerialUtils.append(out, o, map);
db31c358
NR
55 return this;
56 }
db31c358 57}