org.apache.axiom.attachments.impl
Class BufferUtils

java.lang.Object
  extended by org.apache.axiom.attachments.impl.BufferUtils

public class BufferUtils
extends java.lang.Object

Attachment processing uses a lot of buffers. The BufferUtils class attempts to reuse buffers to prevent excessive GarbageCollection


Field Summary
private static byte[] _cacheBuffer
           
private static boolean _cacheBufferInUse
           
private static java.nio.ByteBuffer _cacheByteBuffer
           
private static boolean _cacheByteBufferInUse
           
(package private) static int BUFFER_LEN
           
(package private) static boolean ENABLE_FILE_CHANNEL
           
private static org.apache.commons.logging.Log log
           
 
Constructor Summary
BufferUtils()
           
 
Method Summary
static int doesDataHandlerExceedLimit(javax.activation.DataHandler dh, int limit)
          The method checks to see if attachment is eligble for optimization.
private static java.io.InputStream getInputStream(javax.activation.DataHandler dataHandlerObject)
           
private static byte[] getTempBuffer()
           
private static java.nio.ByteBuffer getTempByteBuffer()
           
static boolean inputStream2FileOutputStream(java.io.InputStream is, java.io.FileOutputStream fos)
          Opimized writing to FileOutputStream using a channel
static void inputStream2OutputStream(java.io.InputStream is, java.io.OutputStream os)
          Private utility to write the InputStream contents to the OutputStream.
static int inputStream2OutputStream(java.io.InputStream is, java.io.OutputStream os, int limit)
           
private static void releaseTempBuffer(byte[] buffer)
           
private static void releaseTempByteBuffer(java.nio.ByteBuffer buffer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

BUFFER_LEN

static int BUFFER_LEN

ENABLE_FILE_CHANNEL

static boolean ENABLE_FILE_CHANNEL

_cacheBuffer

private static byte[] _cacheBuffer

_cacheBufferInUse

private static boolean _cacheBufferInUse

_cacheByteBuffer

private static java.nio.ByteBuffer _cacheByteBuffer

_cacheByteBufferInUse

private static boolean _cacheByteBufferInUse
Constructor Detail

BufferUtils

public BufferUtils()
Method Detail

inputStream2OutputStream

public static void inputStream2OutputStream(java.io.InputStream is,
                                            java.io.OutputStream os)
                                     throws java.io.IOException
Private utility to write the InputStream contents to the OutputStream.

Parameters:
is -
os -
Throws:
java.io.IOException

inputStream2OutputStream

public static int inputStream2OutputStream(java.io.InputStream is,
                                           java.io.OutputStream os,
                                           int limit)
                                    throws java.io.IOException
Parameters:
is - InputStream
os - OutputStream
limit - maximum number of bytes to read
Returns:
total ytes read
Throws:
java.io.IOException

inputStream2FileOutputStream

public static boolean inputStream2FileOutputStream(java.io.InputStream is,
                                                   java.io.FileOutputStream fos)
                                            throws java.io.IOException
Opimized writing to FileOutputStream using a channel

Parameters:
is -
fos -
Returns:
false if lock was not aquired
Throws:
java.io.IOException

doesDataHandlerExceedLimit

public static int doesDataHandlerExceedLimit(javax.activation.DataHandler dh,
                                             int limit)
The method checks to see if attachment is eligble for optimization. An attachment is eligible for optimization if and only if the size of the attachment is greated then the optimzation threshold size limit. if the Content represented by DataHandler has size less than the optimize threshold size, the attachment will not be eligible for optimization, instead it will be inlined. returns 1 if DataHandler data is bigger than limit. returns 0 if DataHandler data is smaller. return -1 if an error occurs or unsupported.

Parameters:
in -
Returns:
Throws:
java.io.IOException

getInputStream

private static java.io.InputStream getInputStream(javax.activation.DataHandler dataHandlerObject)
                                           throws OMException
Throws:
OMException

getTempBuffer

private static byte[] getTempBuffer()

releaseTempBuffer

private static void releaseTempBuffer(byte[] buffer)

getTempByteBuffer

private static java.nio.ByteBuffer getTempByteBuffer()

releaseTempByteBuffer

private static void releaseTempByteBuffer(java.nio.ByteBuffer buffer)