Java DataOutputStream Write Object writeObjectToStream(Object obj, DataOutputStream data)

Here you can find the source of writeObjectToStream(Object obj, DataOutputStream data)

Description

write Object To Stream

License

LGPL

Declaration

private static void writeObjectToStream(Object obj, DataOutputStream data) throws IOException 

Method Source Code

//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
    }
}

Related

  1. writeObject(DataOutputStream dos, Object o)
  2. writeObject(final DataOutputStream out, final Serializable object)
  3. writeObjectToStream(Object obj, DataOutputStream data)