Java DataOutputStream Write Object writeObject(final DataOutputStream out, final Serializable object)

Here you can find the source of writeObject(final DataOutputStream out, final Serializable object)

Description

write Object

License

LGPL

Declaration

public static void writeObject(final DataOutputStream out, final Serializable object) throws IOException 

Method Source Code

//package com.java2s;
/*// ww w  .j a v  a2  s . c o  m
 * Cacheonix Systems licenses this file to You under the LGPL 2.1
 * (the "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *      http://www.cacheonix.org/products/cacheonix/license-lgpl-2.1.htm
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.DataOutputStream;

import java.io.IOException;

import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
    public static void writeObject(final ObjectOutput out, final Object result) throws IOException {
        // REVIEWME: simeshev@cacheonix.org - 2009-08-06 -> handling nulls, ints and exceptions
        out.writeObject(result);
    }

    public static void writeObject(final DataOutputStream out, final Serializable object) throws IOException {

        if (object == null) {
            out.writeBoolean(true); // is null
        } else {
            out.writeBoolean(false);
            final ObjectOutputStream oos = new ObjectOutputStream(out);
            oos.writeObject(object);
            oos.flush();
            oos.close();
        }
    }

    public static void writeBoolean(final DataOutputStream out, final Boolean aBoolean) throws IOException {

        if (aBoolean == null) {

            out.writeBoolean(true);
        } else {

            out.writeBoolean(false);
            out.writeBoolean(aBoolean.booleanValue());
        }
    }
}

Related

  1. writeObject(DataOutputStream dos, Object o)
  2. writeObjectToStream(Object obj, DataOutputStream data)
  3. writeObjectToStream(Object obj, DataOutputStream data)