Package org.apache.axis.attachments
Class ManagedMemoryDataSource
java.lang.Object
org.apache.axis.attachments.ManagedMemoryDataSource
- All Implemented Interfaces:
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.
- Author:
- Rick Rineholt
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BufferedOutputStreamThis is the cached disk stream.protected booleanIf true the source input stream is now closed.protected StringThe content type.protected byte[]Hold the last memory buffer.protected intThe number of bytes written to the above buffer.protected booleanField debugEnabledprotected booleanFlag to show if the resources behind this have been deleted.protected FileField diskCacheFileprotected static org.apache.commons.logging.LogField is_logprotected static org.apache.commons.logging.LogField logstatic final intField MAX_MEMORY_DISK_CACHEDprotected intField maxCachedprotected LinkedListThe linked list to hold the in memory buffers.static final intField MIN_MEMORY_DISK_CACHEDstatic final intField READ_CHUNK_SZprotected WeakHashMapField readersprotected longThe total size in bytes in this data source. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor ManagedMemoryDataSource.ManagedMemoryDataSource(InputStream ss, int maxCached, String contentType) Create a new boundary stream.ManagedMemoryDataSource(InputStream ss, int maxCached, String contentType, boolean readall) Create a new boundary stream. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclose()This method is a low level write.booleandelete()protected voidfinalize()protected voidRoutine to flush data to disk if is in memory.This method returns the MIME type of the data in the form of a string.get the filename of the content if it is cached to disk.This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.getName()This will flush any memory source to disk and provide the name of the file if desired.This method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so.static voidMethod mainprotected voidwrite(byte[] data) Write bytes to the stream.protected voidwrite(byte[] data, int length) This method is a low level write.
-
Field Details
-
log
protected static org.apache.commons.logging.Log logField log -
contentType
The content type. This defaults toapplication/octet-stream. -
MIN_MEMORY_DISK_CACHED
public static final int MIN_MEMORY_DISK_CACHEDField MIN_MEMORY_DISK_CACHED- See Also:
-
MAX_MEMORY_DISK_CACHED
public static final int MAX_MEMORY_DISK_CACHEDField MAX_MEMORY_DISK_CACHED- See Also:
-
maxCached
protected int maxCachedField maxCached -
diskCacheFile
Field diskCacheFile -
readers
Field readers -
deleted
protected boolean deletedFlag to show if the resources behind this have been deleted. -
READ_CHUNK_SZ
public static final int READ_CHUNK_SZField READ_CHUNK_SZ- See Also:
-
debugEnabled
protected boolean debugEnabledField debugEnabled -
memorybuflist
The linked list to hold the in memory buffers. -
currentMemoryBuf
protected byte[] currentMemoryBufHold the last memory buffer. -
currentMemoryBufSz
protected int currentMemoryBufSzThe number of bytes written to the above buffer. -
totalsz
protected long totalszThe total size in bytes in this data source. -
cachediskstream
This is the cached disk stream. -
closed
protected boolean closedIf true the source input stream is now closed. -
is_log
protected static org.apache.commons.logging.Log is_logField is_log
-
-
Constructor Details
-
ManagedMemoryDataSource
protected ManagedMemoryDataSource()Constructor ManagedMemoryDataSource. -
ManagedMemoryDataSource
public ManagedMemoryDataSource(InputStream ss, int maxCached, String contentType) throws IOException Create 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:
IOException
-
ManagedMemoryDataSource
public ManagedMemoryDataSource(InputStream ss, int maxCached, String contentType, boolean readall) throws IOException Create 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:
IOException
-
-
Method Details
-
getContentType
This method returns the MIME type of the data in the form of a string.- Specified by:
getContentTypein interfaceDataSource- Returns:
- The mime type.
-
getInputStream
This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.- Specified by:
getInputStreamin interfaceDataSource- Returns:
- the java.io.InputStream for the data source.
- Throws:
IOException
-
getName
This will flush any memory source to disk and provide the name of the file if desired.- Specified by:
getNamein interfaceDataSource- Returns:
- the name of the file of the stream
-
getOutputStream
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:
getOutputStreamin interfaceDataSource- Returns:
- always
null - Throws:
IOException
-
write
Write bytes to the stream.- Parameters:
data- all bytes of this array are written to the stream- Throws:
IOException- if there was a problem writing the data
-
write
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.- Parameters:
data-length-- Throws:
IOException
-
close
This method is a low level write. Close the stream.- Throws:
IOException
-
finalize
-
flushToDisk
Routine to flush data to disk if is in memory.- Throws:
IOExceptionFileNotFoundException
-
delete
public boolean delete() -
main
Method main- Parameters:
arg-
-
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
-