Java ByteArrayOutputStream Write Object writeObjectToStream(Object sourceObject, ByteArrayOutputStream baos)

Here you can find the source of writeObjectToStream(Object sourceObject, ByteArrayOutputStream baos)

Description

write Object To Stream

License

Open Source License

Declaration

private static <T> void writeObjectToStream(Object sourceObject,
            ByteArrayOutputStream baos) throws IOException 

Method Source Code

//package com.java2s;
/*/*from  w  w w. j  av  a 2 s .c om*/
 * Copyright (c) 2015 Goldman Sachs.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    private static <T> void writeObjectToStream(Object sourceObject,
            ByteArrayOutputStream baos) throws IOException {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(baos);
        try {
            objectOutputStream.writeObject(sourceObject);
            objectOutputStream.flush();
            objectOutputStream.close();
        } finally {
            objectOutputStream.close();
        }
    }
}

Related

  1. writeObjectToStream(Object sourceObject, ByteArrayOutputStream baos)