Package 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.DataSourceThis class allows small attachments to be cached in memory, while large ones are cached out. It implements a Java Activiation Data source interface.- Author:
- Rick Rineholt
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.BufferedOutputStreamcachediskstreamThis is the cached disk stream.protected booleanclosedIf true the source input stream is now closed.protected java.lang.StringcontentTypeThe content type.protected byte[]currentMemoryBufHold the last memory buffer.protected intcurrentMemoryBufSzThe number of bytes written to the above buffer.protected booleandebugEnabledField debugEnabledprotected booleandeletedFlag to show if the resources behind this have been deleted.protected java.io.FilediskCacheFileField diskCacheFileprotected static org.apache.commons.logging.Logis_logField is_logprotected static org.apache.commons.logging.LoglogField logstatic intMAX_MEMORY_DISK_CACHEDField MAX_MEMORY_DISK_CACHEDprotected intmaxCachedField maxCachedprotected java.util.LinkedListmemorybuflistThe linked list to hold the in memory buffers.static intMIN_MEMORY_DISK_CACHEDField MIN_MEMORY_DISK_CACHEDstatic intREAD_CHUNK_SZField READ_CHUNK_SZprotected java.util.WeakHashMapreadersField readersprotected longtotalszThe total size in bytes in this data source.
-
Constructor Summary
Constructors Modifier Constructor Description protectedManagedMemoryDataSource()Constructor 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclose()This method is a low level write.booleandelete()protected voidfinalize()protected voidflushToDisk()Routine to flush data to disk if is in memory.java.lang.StringgetContentType()This method returns the MIME type of the data in the form of a string.java.io.FilegetDiskCacheFile()get the filename of the content if it is cached to disk.java.io.InputStreamgetInputStream()This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.java.lang.StringgetName()This will flush any memory source to disk and provide the name of the file if desired.java.io.OutputStreamgetOutputStream()This method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so.static voidmain(java.lang.String[] arg)Method mainprotected voidwrite(byte[] data)Write bytes to the stream.protected voidwrite(byte[] data, int length)This method is a low level write.
-
-
-
Field Detail
-
log
protected static org.apache.commons.logging.Log log
Field log
-
contentType
protected java.lang.String contentType
The content type. This defaults toapplication/octet-stream.
-
MIN_MEMORY_DISK_CACHED
public static final int MIN_MEMORY_DISK_CACHED
Field MIN_MEMORY_DISK_CACHED- See Also:
- Constant Field Values
-
MAX_MEMORY_DISK_CACHED
public static final int MAX_MEMORY_DISK_CACHED
Field MAX_MEMORY_DISK_CACHED- See Also:
- Constant Field Values
-
maxCached
protected int maxCached
Field maxCached
-
diskCacheFile
protected java.io.File diskCacheFile
Field diskCacheFile
-
readers
protected java.util.WeakHashMap readers
Field readers
-
deleted
protected boolean deleted
Flag to show if the resources behind this have been deleted.
-
READ_CHUNK_SZ
public static final int READ_CHUNK_SZ
Field READ_CHUNK_SZ- See Also:
- Constant Field Values
-
debugEnabled
protected boolean debugEnabled
Field debugEnabled
-
memorybuflist
protected java.util.LinkedList memorybuflist
The linked list to hold the in memory buffers.
-
currentMemoryBuf
protected byte[] currentMemoryBuf
Hold the last memory buffer.
-
currentMemoryBufSz
protected int currentMemoryBufSz
The number of bytes written to the above buffer.
-
totalsz
protected long totalsz
The total size in bytes in this data source.
-
cachediskstream
protected java.io.BufferedOutputStream cachediskstream
This is the cached disk stream.
-
closed
protected boolean closed
If true the source input stream is now closed.
-
is_log
protected static org.apache.commons.logging.Log is_log
Field is_log
-
-
Constructor Detail
-
ManagedMemoryDataSource
protected ManagedMemoryDataSource()
Constructor ManagedMemoryDataSource.
-
ManagedMemoryDataSource
public ManagedMemoryDataSource(java.io.InputStream ss, int maxCached, java.lang.String contentType) throws java.io.IOExceptionCreate a new boundary stream.- Parameters:
ss- is the source input stream that is used to create this data source.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.- Throws:
java.io.IOException
-
ManagedMemoryDataSource
public ManagedMemoryDataSource(java.io.InputStream ss, int maxCached, java.lang.String contentType, boolean readall) throws java.io.IOExceptionCreate a new boundary stream.- Parameters:
ss- is the source input stream that is used to create this data source.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.- Throws:
java.io.IOException
-
-
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:
getContentTypein interfacejavax.activation.DataSource- Returns:
- The mime type.
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionThis method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.- Specified by:
getInputStreamin interfacejavax.activation.DataSource- Returns:
- the java.io.InputStream for the data source.
- Throws:
java.io.IOException
-
getName
public java.lang.String getName()
This will flush any memory source to disk and provide the name of the file if desired.- Specified by:
getNamein interfacejavax.activation.DataSource- Returns:
- the name of the file of the stream
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOExceptionThis 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:
getOutputStreamin interfacejavax.activation.DataSource- Returns:
- always
null - Throws:
java.io.IOException
-
write
protected void write(byte[] data) throws java.io.IOExceptionWrite bytes to the stream.- Parameters:
data- all bytes of this array are written to the stream- Throws:
java.io.IOException- if there was a problem writing the data
-
write
protected void write(byte[] data, int length) throws java.io.IOExceptionThis method is a low level write. Note it is designed to in the future to allow streaming to both memory AND to disk simultaneously.- Parameters:
data-length-- Throws:
java.io.IOException
-
close
protected void close() throws java.io.IOExceptionThis method is a low level write. Close the stream.- Throws:
java.io.IOException
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
flushToDisk
protected void flushToDisk() throws java.io.IOException, java.io.FileNotFoundExceptionRoutine to flush data to disk if is in memory.- Throws:
java.io.IOExceptionjava.io.FileNotFoundException
-
delete
public boolean delete()
-
main
public static void main(java.lang.String[] arg)
Method main- Parameters:
arg-
-
getDiskCacheFile
public java.io.File getDiskCacheFile()
get the filename of the content if it is cached to disk.- Returns:
- file object pointing to file, or null for memory-stored content
-
-