- if (CustomSerializer.isCustom(encodedValue)) {
- // custom:TYPE_NAME:"content is String-encoded"
- String type = CustomSerializer.typeOf(encodedValue);
- if (customTypes.containsKey(type)) {
- return customTypes.get(type).decode(encodedValue);
+ if (CustomSerializer.isCustom(encodedValue)) {
+ // custom:TYPE_NAME:"content is String-encoded"
+ String type = CustomSerializer.typeOf(encodedValue);
+ if (customTypes.containsKey(type)) {
+ // TODO: we should start with a stream
+ InputStream streamEncodedValue = new ByteArrayInputStream(
+ StringUtils.getBytes(encodedValue));
+ try {
+ return customTypes.get(type).decode(streamEncodedValue);
+ } finally {
+ streamEncodedValue.close();
+ }
+ }
+ throw new IOException("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);