Java Utililty Methods DataOutputStream Write Object

List of utility methods to do DataOutputStream Write Object

Description

The list of methods to do DataOutputStream Write Object are organized into topic(s).

Method

voidwriteObject(DataOutputStream dos, Object o)
write Object
ByteArrayOutputStream bout = new ByteArrayOutputStream(20000);
try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));) {
    out.writeObject(o);
dos.writeInt(bout.size());
dos.write(bout.toByteArray());
dos.flush();
voidwriteObject(final DataOutputStream out, final Serializable object)
write Object
if (object == null) {
    out.writeBoolean(true); 
} else {
    out.writeBoolean(false);
    final ObjectOutputStream oos = new ObjectOutputStream(out);
    oos.writeObject(object);
    oos.flush();
    oos.close();
...
voidwriteObjectToStream(Object obj, DataOutputStream data)
write Object To Stream
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)) {
...
voidwriteObjectToStream(Object obj, DataOutputStream data)
write Object To Stream
Class objClass = obj.getClass();
if (objClass.equals(Integer.class)) {
    data.writeInt((Integer) obj);
} else if (objClass.equals(String.class)) {
    data.writeUTF((String) obj);