com.liferay.portal.kernel.io
Class RestrictedByteArrayCacheOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.liferay.portal.kernel.io.RestrictedByteArrayCacheOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class RestrictedByteArrayCacheOutputStream
extends java.io.OutputStream

Author:
Shuyang Zhou

Nested Class Summary
static interface RestrictedByteArrayCacheOutputStream.FlushPreAction
           
 
Field Summary
protected  byte[] cache
           
protected  int cacheCapacity
           
protected  RestrictedByteArrayCacheOutputStream.FlushPreAction flushPreAction
           
protected  int index
           
protected  java.io.OutputStream outputStream
           
protected  boolean overflowed
           
 
Constructor Summary
RestrictedByteArrayCacheOutputStream(java.io.OutputStream outputStream, int initialCacheSize, int cacheCapacity, RestrictedByteArrayCacheOutputStream.FlushPreAction flushPreAction)
           
RestrictedByteArrayCacheOutputStream(java.io.OutputStream outputStream, int cacheCapacity, RestrictedByteArrayCacheOutputStream.FlushPreAction flushPreAction)
           
 
Method Summary
protected  void ensureCacheSize(int newIndex)
           
 void flush()
           
 int getCacheCapacity()
           
 boolean isOverflowed()
           
 void reset()
           
 int size()
           
 byte[] toByteArray()
           
 byte[] unsafeGetByteArray()
           
 java.nio.ByteBuffer unsafeGetByteBuffer()
           
 void write(byte[] bytes)
           
 void write(byte[] bytes, int offset, int length)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected byte[] cache

cacheCapacity

protected int cacheCapacity

flushPreAction

protected RestrictedByteArrayCacheOutputStream.FlushPreAction flushPreAction

index

protected int index

outputStream

protected java.io.OutputStream outputStream

overflowed

protected boolean overflowed
Constructor Detail

RestrictedByteArrayCacheOutputStream

public RestrictedByteArrayCacheOutputStream(java.io.OutputStream outputStream,
                                            int cacheCapacity,
                                            RestrictedByteArrayCacheOutputStream.FlushPreAction flushPreAction)

RestrictedByteArrayCacheOutputStream

public RestrictedByteArrayCacheOutputStream(java.io.OutputStream outputStream,
                                            int initialCacheSize,
                                            int cacheCapacity,
                                            RestrictedByteArrayCacheOutputStream.FlushPreAction flushPreAction)
Method Detail

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

getCacheCapacity

public int getCacheCapacity()

isOverflowed

public boolean isOverflowed()

reset

public void reset()

size

public int size()

toByteArray

public byte[] toByteArray()

unsafeGetByteArray

public byte[] unsafeGetByteArray()

unsafeGetByteBuffer

public java.nio.ByteBuffer unsafeGetByteBuffer()

write

public void write(byte[] bytes)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] bytes,
                  int offset,
                  int length)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

ensureCacheSize

protected void ensureCacheSize(int newIndex)