FileDocCategorySizeDatePackage
File_Persistent_Object_Repository.javaAPI DocApache James 2.3.14864Fri Jan 12 12:56:24 GMT 2007org.apache.james.mailrepository.filepair

File_Persistent_Object_Repository

public class File_Persistent_Object_Repository extends AbstractFileRepository implements org.apache.avalon.cornerstone.services.store.ObjectRepository
This is a simple implementation of persistent object store using object serialization on the file system.

Fields Summary
Constructors Summary
Methods Summary
public synchronized java.lang.Objectget(java.lang.String key)
Get the object associated to the given unique key.

        try
        {
            final InputStream inputStream = getInputStream( key );

            if( inputStream == null )
                  throw new NullPointerException("Null input stream returned for key: " + key );
            try
            {
                final ObjectInputStream stream = new ObjectInputStream( inputStream );

                if( stream == null )
                  throw new NullPointerException("Null stream returned for key: " + key );

                final Object object = stream.readObject();
                if( DEBUG )
                {
                    getLogger().debug( "returning object " + object + " for key " + key );
                }
                return object;
            }
            finally
            {
                inputStream.close();
            }
        }
        catch( final Throwable e )
        {
            throw new RuntimeException(
              "Exception caught while retrieving an object, cause: " + e.toString() );
        }
    
public synchronized java.lang.Objectget(java.lang.String key, java.lang.ClassLoader classLoader)

        try
        {
            final InputStream inputStream = getInputStream( key );

            if( inputStream == null )
                  throw new NullPointerException("Null input stream returned for key: " + key );

            try
            {
                final ObjectInputStream stream = new ClassLoaderObjectInputStream( classLoader, inputStream );

                if( stream == null )
                  throw new NullPointerException("Null stream returned for key: " + key );

                final Object object = stream.readObject();

                if( DEBUG )
                {
                    getLogger().debug( "returning object " + object + " for key " + key );
                }
                return object;
            }
            finally
            {
                inputStream.close();
            }
        }
        catch( final Throwable e )
        {
            throw new RuntimeException( "Exception caught while retrieving an object: " + e );
        }

    
protected java.lang.StringgetExtensionDecorator()

        return ".FileObjectStore";
    
public synchronized voidput(java.lang.String key, java.lang.Object value)
Store the given object and associates it to the given key

        try
        {
            final OutputStream outputStream = getOutputStream( key );

            try
            {
                final ObjectOutputStream stream = new ObjectOutputStream( outputStream );
                stream.writeObject( value );
                if( DEBUG ) getLogger().debug( "storing object " + value + " for key " + key );
            }
            finally
            {
                outputStream.close();
            }
        }
        catch( final Exception e )
        {
            throw new RuntimeException( "Exception caught while storing an object: " + e );
        }