org.apache.axis.attachments
Class ManagedMemoryDataSource

java.lang.Object
  |
  +--org.apache.axis.attachments.ManagedMemoryDataSource
All Implemented Interfaces:
javax.activation.DataSource

public class ManagedMemoryDataSource
extends java.lang.Object
implements javax.activation.DataSource

This class allows small attachments to be cached in memory, while large ones are cached out. It implements a Java Activiation Data source interface. TODO TODO TODO need to delete cached out data sources after a service ends.


Field Summary
protected  java.io.BufferedOutputStream cachediskstream
           
protected  boolean closed
           
protected  java.lang.String contentType
           
protected  byte[] currentMemoryBuf
           
protected  int currentMemoryBufSz
           
protected  boolean debugEnabled
           
protected  boolean deleted
           
protected  java.io.File diskCacheFile
           
static int MAX_MEMORY_DISK_CACHED
           
protected  int maxCached
           
protected  java.util.LinkedList memorybuflist
           
static int READ_CHUNK_SZ
           
protected  java.util.WeakHashMap readers
           
protected  int totalsz
           
 
Constructor Summary
protected ManagedMemoryDataSource()
           
  ManagedMemoryDataSource(java.io.InputStream ss, int maxCached, java.lang.String contentType)
          Create a new boundary stream;
  ManagedMemoryDataSource(java.io.InputStream ss, int maxCached, java.lang.String contentType, boolean readall)
          Create a new boundary stream;
 
Method Summary
protected  void close()
          This method is a low level write.
 boolean delete()
           
protected  void finalize()
           
protected  void flushToDisk()
          Routine to flush data to disk if is in memory.
 java.lang.String getContentType()
          This method returns the MIME type of the data in the form of a string.
 java.io.InputStream getInputStream()
          This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.
 java.lang.String getName()
          This will flush any memory source to disk and provide the name of the file if desired.
 java.io.OutputStream getOutputStream()
          This method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so.
static void main(java.lang.String[] arg)
           
protected  void write(byte[] data)
          Write bytes to the stream.
protected  void write(byte[] data, int length)
          This method is a low level write.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contentType

protected java.lang.String contentType

MAX_MEMORY_DISK_CACHED

public static final int MAX_MEMORY_DISK_CACHED

maxCached

protected int maxCached

diskCacheFile

protected java.io.File diskCacheFile

readers

protected java.util.WeakHashMap readers

deleted

protected boolean deleted

READ_CHUNK_SZ

public static final int READ_CHUNK_SZ

debugEnabled

protected boolean debugEnabled

memorybuflist

protected java.util.LinkedList memorybuflist

currentMemoryBuf

protected byte[] currentMemoryBuf

currentMemoryBufSz

protected int currentMemoryBufSz

totalsz

protected int totalsz

cachediskstream

protected java.io.BufferedOutputStream cachediskstream

closed

protected boolean closed
Constructor Detail

ManagedMemoryDataSource

protected ManagedMemoryDataSource()

ManagedMemoryDataSource

public ManagedMemoryDataSource(java.io.InputStream ss,
                               int maxCached,
                               java.lang.String contentType)
                        throws java.io.IOException
Create a new boundary stream;
Parameters:
ss - is the source input stream that is used to create this data source..
readbufsz - lets you have some control over the amount of buffering.
maxCached - This is the max memory that is to be used to cache the data.
contentType - the mime type for this data stream. by buffering you can some effiency in searching.

ManagedMemoryDataSource

public ManagedMemoryDataSource(java.io.InputStream ss,
                               int maxCached,
                               java.lang.String contentType,
                               boolean readall)
                        throws java.io.IOException
Create a new boundary stream;
Parameters:
ss - is the source input stream that is used to create this data source..
readbufsz - lets you have some control over the amount of buffering.
maxCached - This is the max memory that is to be used to cache the data.
contentType - the mime type for this data stream. by buffering you can some effiency in searching.
readall - if true will read in the whole source.
Method Detail

getContentType

public java.lang.String getContentType()
This method returns the MIME type of the data in the form of a string.
Specified by:
getContentType in interface javax.activation.DataSource
Returns:
The mime type.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.
Specified by:
getInputStream in interface javax.activation.DataSource
Returns:
the java.io.InputStream for the data source.

getName

public java.lang.String getName()
This will flush any memory source to disk and provide the name of the file if desired. Return the name of the file of the stream.
Specified by:
getName in interface javax.activation.DataSource

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
This method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so. NOT SUPPORTED, not need for axis, data sources are create by constructors.
Specified by:
getOutputStream in interface javax.activation.DataSource

write

protected void write(byte[] data)
              throws java.io.IOException
Write bytes to the stream.
Parameters:
data - all bytes of this array are written to the stream.

write

protected void write(byte[] data,
                     int length)
              throws java.io.IOException
This method is a low level write. Note it is designed to in the future to allow streaming to both memory AND to disk simultaneously.

close

protected void close()
              throws java.io.IOException
This method is a low level write. Close the stream.

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object

flushToDisk

protected void flushToDisk()
                    throws java.io.IOException,
                           java.io.FileNotFoundException
Routine to flush data to disk if is in memory.

delete

public boolean delete()

main

public static void main(java.lang.String[] arg)


Copyright © 2001 Apache XML Project. All Rights Reserved.