org.apache.axis2.saaj.util
Class SAAJDataSource

java.lang.Object
  extended by org.apache.axis2.saaj.util.SAAJDataSource
All Implemented Interfaces:
javax.activation.DataSource

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


Field Summary
protected  java.io.BufferedOutputStream cachediskstream
          This is the cached disk stream.
protected  boolean closed
          If true the source input stream is now closed.
protected  java.lang.String contentType
          The content type.
protected  byte[] currentMemoryBuf
          Hold the last memory buffer.
protected  int currentMemoryBufSz
          The number of bytes written to the above buffer.
protected  boolean deleted
          Flag to show if the resources behind this have been deleted.
protected  java.io.File diskCacheFile
          Field diskCacheFile
static int MAX_MEMORY_DISK_CACHED
          Field MAX_MEMORY_DISK_CACHED
protected  int maxCached
          Field maxCached
protected  java.util.LinkedList memorybuflist
          The linked list to hold the in memory buffers.
static int MIN_MEMORY_DISK_CACHED
          Field MIN_MEMORY_DISK_CACHED
static int READ_CHUNK_SZ
          Field READ_CHUNK_SZ
protected  java.util.WeakHashMap readers
          Field readers
protected  long totalsz
          The total size in bytes in this data source.
 
Constructor Summary
protected SAAJDataSource()
          Constructor SAAJDataSource.
  SAAJDataSource(java.io.InputStream ss, int maxCached, java.lang.String contentType)
          Create a new boundary stream.
  SAAJDataSource(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.
protected  void flushToDisk()
          Routine to flush data to disk if is in memory.
 java.lang.String getContentType()
           
 java.io.File getDiskCacheFile()
          get the filename of the content if it is cached to disk.
 java.io.InputStream getInputStream()
           
 java.lang.String getName()
           
 java.io.OutputStream getOutputStream()
           
protected  void write(byte[] data)
          Write bytes to the stream.
protected  void write(byte[] data, int length)
          This method is a low level write.
protected  void writeToMemory(byte[] data, int length)
          This method is a low level write.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contentType

protected java.lang.String contentType
The content type. This defaults to application/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

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.

Constructor Detail

SAAJDataSource

protected SAAJDataSource()
Constructor SAAJDataSource.


SAAJDataSource

public SAAJDataSource(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.
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

SAAJDataSource

public SAAJDataSource(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.
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()
              throws java.io.IOException
This method is a low level write. Close the stream.

Throws:
java.io.IOException

flushToDisk

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

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

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
Throws:
java.io.IOException - if there was a problem writing the data

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.

Parameters:
data -
length -
Throws:
java.io.IOException

writeToMemory

protected void writeToMemory(byte[] data,
                             int length)
                      throws java.io.IOException
This method is a low level write. Writes only to memory

Parameters:
data -
length -
Throws:
java.io.IOException

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

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Specified by:
getInputStream in interface javax.activation.DataSource
Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Specified by:
getOutputStream in interface javax.activation.DataSource
Throws:
java.io.IOException

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface javax.activation.DataSource

getName

public java.lang.String getName()
Specified by:
getName in interface javax.activation.DataSource


Copyright © 2007 Apache Web Services Project. All Rights Reserved.