+ /**
+ * Append the exported items in a serialised form into the given
+ * {@link StringBuilder}.
+ *
+ * @param toBuilder
+ * the {@link StringBuilder}
+ * @param b64
+ * TRUE to have BASE64-coded content, FALSE to have raw content,
+ * NULL to let the system decide
+ * @param zip
+ * TRUE to zip the BASE64 output if the output is indeed in
+ * BASE64 format, FALSE not to
+ */
+ public void appendTo(StringBuilder toBuilder, Boolean b64, boolean zip) {
+ if (b64 == null && builder.length() < 128) {
+ b64 = false;
+ }
+
+ if (b64 == null || b64) {
+ try {
+ String zipped = StringUtils.base64(builder.toString(), zip);
+ if (b64 != null || zipped.length() < builder.length() - 4) {
+ toBuilder.append(zip ? "ZIP:" : "B64:");
+ toBuilder.append(zipped);
+ return;
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Base64 conversion of data failed, maybe not enough memory?",
+ e);
+ }
+ }
+
+ toBuilder.append(builder);
+ }
+