Java OutputStream Write serialize(Object o, OutputStream out)

Here you can find the source of serialize(Object o, OutputStream out)

Description

Serializes the given object to the given output stream.

License

Open Source License

Parameter

Parameter Description
o a serializable object.
out the stream to write the object to.

Exception

Parameter Description
IOException if an I/O exception occured.

Declaration

public static void serialize(Object o, OutputStream out) throws IOException 

Method Source Code

//package com.java2s;
/*//from  w  w w  .j  a  v  a 2s. c  o m
 * Copyright (c) 2001-2002, Marco Hunsicker. All rights reserved.
 *
 * This software is distributable under the BSD license. See the terms of the
 * BSD license in the documentation provided with this software.
 */

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class Main {
    /**
     * Serializes the given object to the given output stream.
     *
     * @param o a serializable object.
     * @param out the stream to write the object to.
     *
     * @throws IOException if an I/O exception occured.
     */
    public static void serialize(Object o, OutputStream out) throws IOException {
        ObjectOutputStream oout = new ObjectOutputStream(out);

        try {
            oout.writeObject(o);
        } finally {
            if (oout != null) {
                oout.close();
            }
        }
    }

    /**
     * Serializes the given object to the given file.
     *
     * @param o a serializable object.
     * @param file the file to write the object to.
     *
     * @throws IOException if an I/O exception occured.
     */
    public static void serialize(Object o, File file) throws IOException {
        serialize(o, new BufferedOutputStream(new FileOutputStream(file)));
    }
}

Related

  1. copyFile(InputStream inputStream, OutputStream outputStream)
  2. copyFile(OutputStream os, InputStream is)
  3. copyFile(String fileName, String newFileName)
  4. copyFilePermissions(File source, File target)
  5. serialize(java.io.Serializable serializable, java.io.ObjectOutputStream oos)
  6. serialize(Object obj, OutputStream out)
  7. serialize(Object obj, OutputStream out)
  8. serialize(Object object, OutputStream out)
  9. serialize(Object value, OutputStream targetOutputStream)