X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2FExporter.java;h=2470bde4dace9f6dd0ca73f61373991a4cbd4283;hb=712ddafb749aada41daab85c36ac12f657b2307e;hp=3a6e025739c9faf0893fa2a65f07970012ae8f0e;hpb=8a5c590389f5a6704300a583827ac7ee982a8d73;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/Exporter.java b/src/be/nikiroo/utils/serial/Exporter.java deleted file mode 100644 index 3a6e025..0000000 --- a/src/be/nikiroo/utils/serial/Exporter.java +++ /dev/null @@ -1,91 +0,0 @@ -package be.nikiroo.utils.serial; - -import java.io.NotSerializableException; -import java.util.HashMap; -import java.util.Map; - -import be.nikiroo.utils.StringUtils; - -/** - * A simple class to serialise objects to {@link String}. - *

- * This class does not support inner classes (it does support nested classes, - * though). - * - * @author niki - */ -public class Exporter { - private Map map; - private StringBuilder builder; - - /** - * Create a new {@link Exporter}. - */ - public Exporter() { - map = new HashMap(); - builder = new StringBuilder(); - } - - /** - * Serialise the given object and add it to the list. - *

- * Important: If the operation fails (with a - * {@link NotSerializableException}), the {@link Exporter} will be corrupted - * (will contain bad, most probably not importable data). - * - * @param o - * the object to serialise - * @return this (for easier appending of multiple values) - * - * @throws NotSerializableException - * if the object cannot be serialised (in this case, the - * {@link Exporter} can contain bad, most probably not - * importable data) - */ - public Exporter append(Object o) throws NotSerializableException { - SerialUtils.append(builder, o, map); - return this; - } - - /** - * Clear the current content. - */ - public void clear() { - builder.setLength(0); - map.clear(); - } - - /** - * The exported items in a serialised form. - * - * @param zip - * TRUE to have zipped (and BASE64-coded) content, FALSE to have - * raw content, NULL to let the system decide - * - * @return the items currently in this {@link Exporter} - */ - public String toString(Boolean zip) { - if (zip == null && builder.length() > 128) { - zip = false; - } - - if (zip == null || zip) { - String zipped = "ZIP:" + StringUtils.zip64(builder.toString()); - - if (zip != null || builder.length() < zipped.length()) - return zipped; - } - - return builder.toString(); - } - - /** - * The exported items in a serialised form (possibly zipped). - * - * @return the items currently in this {@link Exporter} - */ - @Override - public String toString() { - return toString(null); - } -} \ No newline at end of file