001 package com.croftsoft.core.io;
002
003 import java.io.*;
004
005 /*********************************************************************
006 * An Encoder and Parser implementation that uses object serialization.
007 *
008 * @version
009 * 2003-05-28
010 * @since
011 * 2003-05-13
012 * @author
013 * <a href="http://www.CroftSoft.com/">David Wallace Croft</a>
014 *********************************************************************/
015
016 public final class SerializableCoder
017 implements Encoder, Parser
018 //////////////////////////////////////////////////////////////////////
019 //////////////////////////////////////////////////////////////////////
020 {
021
022 public static final SerializableCoder INSTANCE
023 = new SerializableCoder ( );
024
025 //////////////////////////////////////////////////////////////////////
026 //////////////////////////////////////////////////////////////////////
027
028 public byte [ ] encode ( Object object )
029 throws IOException
030 //////////////////////////////////////////////////////////////////////
031 {
032 return SerializableLib.compress ( ( Serializable ) object );
033 }
034
035 public Object parse (
036 InputStream inputStream,
037 int contentLength )
038 throws IOException
039 //////////////////////////////////////////////////////////////////////
040 {
041 try
042 {
043 return SerializableLib.load ( inputStream );
044 }
045 catch ( ClassNotFoundException ex )
046 {
047 throw ( IOException ) new IOException ( ).initCause ( ex );
048 }
049 }
050
051 //////////////////////////////////////////////////////////////////////
052 //////////////////////////////////////////////////////////////////////
053
054 private SerializableCoder ( ) { }
055
056 //////////////////////////////////////////////////////////////////////
057 //////////////////////////////////////////////////////////////////////
058 }