+ * Decode the data into an equivalent supported source object.
+ * <p>
+ * A supported object in this context means an object we can directly
+ * encode, like an Integer or a String (see
+ * {@link SerialUtils#decode(String)}.
+ * <p>
+ * Custom objects and arrays are also considered supported here, but
+ * <b>compound objects are not</b>.
+ * <p>
+ * For compound objects, you should use {@link Importer}.
+ *
+ * @param encodedValue
+ * the encoded data, cannot be NULL
+ *
+ * @return the object (can be NULL for NULL encoded values)
+ *
+ * @throws IOException
+ * if the content cannot be converted
+ */
+ static Object decode(BufferedInputStream encodedValue) throws IOException {
+ if (CustomSerializer.isCustom(encodedValue)) {
+ // custom^TYPE^ENCODED_VALUE
+ NextableInputStream content = new NextableInputStream(encodedValue,
+ new NextableInputStreamStep('^'));
+ try {
+ content.next();
+ @SuppressWarnings("unused")
+ String custom = IOUtils.readSmallStream(content);
+ content.next();
+ String type = IOUtils.readSmallStream(content);
+ content.nextAll();
+ if (customTypes.containsKey(type)) {
+ return customTypes.get(type).decode(content);
+ }
+ content.end();
+ throw new IOException("Unknown custom type: " + type);
+ } finally {
+ content.close(false);
+ encodedValue.end();
+ }
+ }
+
+ String encodedString = IOUtils.readSmallStream(encodedValue);
+ return decode(encodedString);
+ }
+
+ /**
+ * Decode the data into an equivalent supported source object.
+ * <p>
+ * A supported object in this context means an object we can directly
+ * encode, like an Integer or a String.
+ * <p>
+ * For custom objects and arrays, you should use
+ * {@link SerialUtils#decode(InputStream)} or directly {@link Importer}.
+ * <p>
+ * For compound objects, you should use {@link Importer}.