org.apache.axis.attachments

Class ManagedMemoryDataSource

public class ManagedMemoryDataSource extends Object implements 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
protected BufferedOutputStreamcachediskstream
This is the cached disk stream.
protected booleanclosed
If true the source input stream is now closed.
protected StringcontentType
The content type.
protected byte[]currentMemoryBuf
Hold the last memory buffer.
protected intcurrentMemoryBufSz
The number of bytes written to the above buffer.
protected booleandebugEnabled
Field debugEnabled
protected booleandeleted
Flag to show if the resources behind this have been deleted.
protected FilediskCacheFile
Field diskCacheFile
protected static Logis_log
Field is_log
protected static Loglog
Field log
protected intmaxCached
Field maxCached
protected LinkedListmemorybuflist
The linked list to hold the in memory buffers.
static intMAX_MEMORY_DISK_CACHED
Field MAX_MEMORY_DISK_CACHED
static intMIN_MEMORY_DISK_CACHED
Field MIN_MEMORY_DISK_CACHED
protected WeakHashMapreaders
Field readers
static intREAD_CHUNK_SZ
Field READ_CHUNK_SZ
protected longtotalsz
The total size in bytes in this data source.
Constructor Summary
protected ManagedMemoryDataSource()
Constructor 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
protected voidclose()
This method is a low level write.
booleandelete()
protected voidfinalize()
protected voidflushToDisk()
Routine to flush data to disk if is in memory.
StringgetContentType()
This method returns the MIME type of the data in the form of a string.
FilegetDiskCacheFile()
get the filename of the content if it is cached to disk.
InputStreamgetInputStream()
This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.
StringgetName()
This will flush any memory source to disk and provide the name of the file if desired.
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(String[] arg)
Method main
protected voidwrite(byte[] data)
Write bytes to the stream.
protected voidwrite(byte[] data, int length)
This method is a low level write.

Field Detail

cachediskstream

protected BufferedOutputStream cachediskstream
This is the cached disk stream.

closed

protected boolean closed
If true the source input stream is now closed.

contentType

protected String contentType
The content type. This defaults to application/octet-stream.

currentMemoryBuf

protected byte[] currentMemoryBuf
Hold the last memory buffer.

currentMemoryBufSz

protected int currentMemoryBufSz
The number of bytes written to the above buffer.

debugEnabled

protected boolean debugEnabled
Field debugEnabled

deleted

protected boolean deleted
Flag to show if the resources behind this have been deleted.

diskCacheFile

protected File diskCacheFile
Field diskCacheFile

is_log

protected static Log is_log
Field is_log

log

protected static Log log
Field log

maxCached

protected int maxCached
Field maxCached

memorybuflist

protected LinkedList memorybuflist
The linked list to hold the in memory buffers.

MAX_MEMORY_DISK_CACHED

public static final int MAX_MEMORY_DISK_CACHED
Field MAX_MEMORY_DISK_CACHED

MIN_MEMORY_DISK_CACHED

public static final int MIN_MEMORY_DISK_CACHED
Field MIN_MEMORY_DISK_CACHED

readers

protected WeakHashMap readers
Field readers

READ_CHUNK_SZ

public static final int READ_CHUNK_SZ
Field READ_CHUNK_SZ

totalsz

protected long totalsz
The total size in bytes in this data source.

Constructor Detail

ManagedMemoryDataSource

protected ManagedMemoryDataSource()
Constructor ManagedMemoryDataSource.

ManagedMemoryDataSource

public ManagedMemoryDataSource(InputStream ss, int maxCached, String contentType)
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: java.io.IOException

ManagedMemoryDataSource

public ManagedMemoryDataSource(InputStream ss, int maxCached, String contentType, boolean readall)
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: java.io.IOException

Method Detail

close

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

Throws: java.io.IOException

delete

public boolean delete()

finalize

protected void finalize()

flushToDisk

protected void flushToDisk()
Routine to flush data to disk if is in memory.

Throws: java.io.IOException java.io.FileNotFoundException

getContentType

public String getContentType()
This method returns the MIME type of the data in the form of a string.

Returns: The mime type.

getDiskCacheFile

public 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

getInputStream

public InputStream getInputStream()
This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.

Returns: the java.io.InputStream for the data source.

Throws: java.io.IOException

getName

public String getName()
This will flush any memory source to disk and provide the name of the file if desired.

Returns: the name of the file of the stream

getOutputStream

public OutputStream 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.

Returns: always null

Throws: java.io.IOException

main

public static void main(String[] arg)
Method main

Parameters: arg

write

protected void write(byte[] data)
Write 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)
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: java.io.IOException

Copyright B) 2005 Apache Web Services Project. All Rights Reserved.