Package de.netseeker.ejoe.adapter

Source Code of de.netseeker.ejoe.adapter.ObjectStreamAdapter

/*********************************************************************
* ObjectStreamAdapter.java
* created on 13.08.2004 by netseeker
* $Source: /cvsroot/ejoe/EJOE/src/de/netseeker/ejoe/adapter/ObjectStreamAdapter.java,v $
* $Date: 2006/12/03 13:54:41 $
* $Revision: 1.18 $
*
* ====================================================================
*
*  Copyright 2005-2006 netseeker aka Michael Manske
*
*  Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
*  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.
* ====================================================================
*
* This file is part of the ejoe framework.
* For more information on the author, please see
* <http://www.manskes.de/>.
*
*********************************************************************/

package de.netseeker.ejoe.adapter;

import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;

/**
* Simple (de)serialize adapter using the standard ObjectInputStream and ObjectOutputStream classes provided by SUN.
*
* @author netseeker aka Michael Manske
* @since 0.3.0
*/
public class ObjectStreamAdapter extends BaseAdapter
{
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     *
     * @see de.netseeker.ejoe.adapter.SerializeAdapter#read(java.io.InputStream)
     */
    public Object read( InputStream in ) throws Exception
    {
        Object obj = null;
        ObjectInputStream oin = new ObjectInputStream( in );

        try
        {
            obj = oin.readObject();
        }
        finally
        {
            if ( oin != null )
            {
                oin.close();
            }
        }

        return obj;
    }

    /*
     * (non-Javadoc)
     *
     * @see de.netseeker.ejoe.adapter.SerializeAdapter#write(java.lang.Object, java.io.OutputStream)
     */
    public void write( Object obj, OutputStream out ) throws Exception
    {
        Serializable target = (Serializable)obj;
        ObjectOutputStream oout = new ObjectOutputStream( out );
        oout.writeObject( target );
        oout.close();
    }
}
TOP

Related Classes of de.netseeker.ejoe.adapter.ObjectStreamAdapter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.