- throw new UnknownFormatConversionException("Unknown custom type: "
- + type);
- } else if (encodedValue.equals("NULL") || encodedValue.equals("null")) {
- return null;
- } else if (encodedValue.endsWith("\"")) {
- return decodeString(encodedValue);
- } else if (encodedValue.equals("true")) {
- return true;
- } else if (encodedValue.equals("false")) {
- return false;
- } else if (encodedValue.endsWith("b")) {
- return Byte.parseByte(cut);
- } else if (encodedValue.endsWith("c")) {
- return decodeString(cut).charAt(0);
- } else if (encodedValue.endsWith("s")) {
- return Short.parseShort(cut);
- } else if (encodedValue.endsWith("L")) {
- return Long.parseLong(cut);
- } else if (encodedValue.endsWith("F")) {
- return Float.parseFloat(cut);
- } else if (encodedValue.endsWith("d")) {
- return Double.parseDouble(cut);
- } else if (encodedValue.endsWith(";")) {
- return decodeEnum(encodedValue);
- } else {
- return Integer.parseInt(encodedValue);
+ }
+
+ 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}.
+ *
+ * @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(String encodedValue) throws IOException {
+ try {
+ String cut = "";
+ if (encodedValue.length() > 1) {
+ cut = encodedValue.substring(1);
+ }
+
+ if (encodedValue.equals("NULL") || encodedValue.equals("null")) {
+ return null;
+ } else if (encodedValue.startsWith("\"")) {
+ return decodeString(encodedValue);
+ } else if (encodedValue.equals("true")) {
+ return true;
+ } else if (encodedValue.equals("false")) {
+ return false;
+ } else if (encodedValue.startsWith("b")) {
+ return Byte.parseByte(cut);
+ } else if (encodedValue.startsWith("c")) {
+ return decodeString(cut).charAt(0);
+ } else if (encodedValue.startsWith("s")) {
+ return Short.parseShort(cut);
+ } else if (encodedValue.startsWith("l")) {
+ return Long.parseLong(cut);
+ } else if (encodedValue.startsWith("f")) {
+ return Float.parseFloat(cut);
+ } else if (encodedValue.startsWith("d")) {
+ return Double.parseDouble(cut);
+ } else if (encodedValue.startsWith("i")) {
+ return Integer.parseInt(cut);
+ } else if (encodedValue.startsWith("E:")) {
+ cut = cut.substring(1);
+ return decodeEnum(cut);
+ } else {
+ throw new IOException("Unrecognized value: " + encodedValue);
+ }
+ } catch (Exception e) {
+ if (e instanceof IOException) {
+ throw (IOException) e;
+ }
+ throw new IOException(e.getMessage(), e);