Package org.apache.axis2.saaj.util
Class SAAJDataSource
- java.lang.Object
-
- org.apache.axis2.saaj.util.SAAJDataSource
-
- All Implemented Interfaces:
DataSource
public class SAAJDataSource extends Object implements DataSource
-
-
Field Summary
Fields Modifier and Type Field Description protected BufferedOutputStreamcachediskstreamThis is the cached disk stream.protected booleanclosedIf true the source input stream is now closed.protected StringcontentTypeThe content type.protected byte[]currentMemoryBufHold the last memory buffer.protected intcurrentMemoryBufSzThe number of bytes written to the above buffer.protected booleandeletedFlag to show if the resources behind this have been deleted.protected FilediskCacheFileField diskCacheFilestatic intMAX_MEMORY_DISK_CACHEDField MAX_MEMORY_DISK_CACHEDprotected intmaxCachedField maxCachedprotected LinkedListmemorybuflistThe linked list to hold the in memory buffers.static intMIN_MEMORY_DISK_CACHEDField MIN_MEMORY_DISK_CACHEDstatic intREAD_CHUNK_SZField READ_CHUNK_SZprotected WeakHashMapreadersField readersprotected longtotalszThe total size in bytes in this data source.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSAAJDataSource()Constructor SAAJDataSource.SAAJDataSource(InputStream ss, int maxCached, String contentType)Create a new boundary stream.SAAJDataSource(InputStream ss, int maxCached, String contentType, boolean readall)Create a new boundary stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclose()This method is a low level write.protected voidflushToDisk()Routine to flush data to disk if is in memory.StringgetContentType()FilegetDiskCacheFile()get the filename of the content if it is cached to disk.InputStreamgetInputStream()StringgetName()OutputStreamgetOutputStream()protected voidwrite(byte[] data)Write bytes to the stream.protected voidwrite(byte[] data, int length)This method is a low level write.protected voidwriteToMemory(byte[] data, int length)This method is a low level write.
-
-
-
Field Detail
-
contentType
protected 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 File diskCacheFile
Field diskCacheFile
-
readers
protected 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
-
memorybuflist
protected 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 BufferedOutputStream cachediskstream
This is the cached disk stream.
-
closed
protected boolean closed
If true the source input stream is now closed.
-
-
Constructor Detail
-
SAAJDataSource
protected SAAJDataSource()
Constructor SAAJDataSource.
-
SAAJDataSource
public SAAJDataSource(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
-
SAAJDataSource
public SAAJDataSource(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 Detail
-
close
protected void close() throws IOExceptionThis method is a low level write. Close the stream.- Throws:
IOException
-
flushToDisk
protected void flushToDisk() throws IOException, FileNotFoundExceptionRoutine to flush data to disk if is in memory.- Throws:
IOExceptionFileNotFoundException
-
write
protected void write(byte[] data) throws IOExceptionWrite 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
protected void write(byte[] data, int length) throws 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:
IOException
-
writeToMemory
protected void writeToMemory(byte[] data, int length) throws IOExceptionThis method is a low level write. Writes only to memory- Parameters:
data-length-- Throws:
IOException
-
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() throws IOException
- Specified by:
getInputStreamin interfaceDataSource- Throws:
IOException
-
getOutputStream
public OutputStream getOutputStream() throws IOException
- Specified by:
getOutputStreamin interfaceDataSource- Throws:
IOException
-
getContentType
public String getContentType()
- Specified by:
getContentTypein interfaceDataSource
-
getName
public String getName()
- Specified by:
getNamein interfaceDataSource
-
-