Esempio n. 1
0
 @SuppressWarnings("unchecked")
 private static void serialize(ByteArrayOutputStream stream, Object obj, String charset) {
   if (obj == null) {
     writeNull(stream);
   } else if (obj instanceof Boolean) {
     writeBoolean(stream, ((Boolean) obj).booleanValue() ? __1 : __0);
   } else if ((obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Integer)) {
     writeInteger(stream, getAsciiBytes(obj));
   } else if (obj instanceof Long) {
     writeDouble(stream, getAsciiBytes(obj));
   } else if (obj instanceof Float) {
     Float f = (Float) obj;
     obj = f.isNaN() ? __NAN : (!f.isInfinite() ? obj : (f.floatValue() > 0 ? __INF : __NINF));
     writeDouble(stream, getAsciiBytes(obj));
   } else if (obj instanceof Double) {
     Double d = (Double) obj;
     obj = d.isNaN() ? __NAN : (!d.isInfinite() ? obj : (d.doubleValue() > 0 ? __INF : __NINF));
     writeDouble(stream, getAsciiBytes(obj));
   } else if ((obj instanceof Character)
       || (obj instanceof String)
       || (obj instanceof StringBuffer)) {
     writeString(stream, getBytes(obj, charset));
   } else if (obj instanceof Map) {
     writeMap(stream, (Map) obj, charset);
   } else if (obj instanceof List) {
     writeList(stream, (List) obj, charset);
   } else {
     System.out.println("Serializer.serialize: The DataType is invalid");
   }
 }