Here you can find the source of writeObjectToStream(Object obj, DataOutputStream data)
private static void writeObjectToStream(Object obj, DataOutputStream data) throws IOException
//package com.java2s; //License from project: LGPL import java.io.DataOutputStream; import java.io.IOException; public class Main { private static void writeObjectToStream(Object obj, DataOutputStream data) throws IOException { Class<? extends Object> objClass = obj.getClass(); if (objClass.equals(Boolean.class)) { data.writeBoolean((Boolean) obj); } else if (objClass.equals(Byte.class)) { data.writeByte((Byte) obj); } else if (objClass.equals(Integer.class)) { data.writeInt((Integer) obj); } else if (objClass.equals(String.class)) { data.writeUTF((String) obj); } else if (objClass.equals(Double.class)) { data.writeDouble((Double) obj); } else if (objClass.equals(Float.class)) { data.writeFloat((Float) obj); } else if (objClass.equals(Long.class)) { data.writeLong((Long) obj); } else if (objClass.equals(Short.class)) { data.writeShort((Short) obj); }//from w w w . j a v a2 s . c o m } }