Here you can find the source of serialize(Object o, OutputStream out)
Parameter | Description |
---|---|
o | a serializable object. |
out | the stream to write the object to. |
Parameter | Description |
---|---|
IOException | if an I/O exception occured. |
public static void serialize(Object o, OutputStream out) throws IOException
//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))); } }