com.planetj.servlet.filter.compression
Class ThresholdOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.planetj.servlet.filter.compression.ThresholdOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

final class ThresholdOutputStream
extends java.io.OutputStream

Author:
Sean Owen

Nested Class Summary
(package private) static interface ThresholdOutputStream.BufferCommitmentCallback
          Implementations of this interface are used to receive notification that this stream has either committed bytes to the "raw" stream (without compression), or has committed bytes to a compressing stream.
 
Field Summary
private  java.io.ByteArrayOutputStream buffer
           
private  ThresholdOutputStream.BufferCommitmentCallback bufferCommitmentCallback
           
private  boolean buffering
           
private  boolean closed
           
private  CompressingOutputStream compressingOutputStream
           
private  CompressingStreamFactory compressingStreamFactory
           
private  CompressingFilterContext context
           
private  boolean forceOut1
           
private  java.io.OutputStream out1
           
private  java.io.OutputStream out2
           
private  int threshold
           
 
Constructor Summary
ThresholdOutputStream(java.io.OutputStream out1, CompressingStreamFactory compressingStreamFactory, CompressingFilterContext context, ThresholdOutputStream.BufferCommitmentCallback thresholdReachedCallback)
           
 
Method Summary
private  void checkClosed()
           
 void close()
           
private  boolean continueBuffering(int numAdditionalBytes)
           
 void flush()
           
private  void flushBufferToStream(java.io.OutputStream out)
           
(package private)  void forceOutputStream1()
           
(package private)  void reset()
           
(package private)  void switchToOutputStream2()
           
 java.lang.String toString()
           
 void write(byte[] b)
           
 void write(byte[] b, int offset, int length)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buffering

private boolean buffering

out1

private final java.io.OutputStream out1

out2

private java.io.OutputStream out2

compressingOutputStream

private CompressingOutputStream compressingOutputStream

compressingStreamFactory

private final CompressingStreamFactory compressingStreamFactory

context

private final CompressingFilterContext context

threshold

private final int threshold

bufferCommitmentCallback

private final ThresholdOutputStream.BufferCommitmentCallback bufferCommitmentCallback

buffer

private java.io.ByteArrayOutputStream buffer

closed

private boolean closed

forceOut1

private boolean forceOut1
Constructor Detail

ThresholdOutputStream

ThresholdOutputStream(java.io.OutputStream out1,
                      CompressingStreamFactory compressingStreamFactory,
                      CompressingFilterContext context,
                      ThresholdOutputStream.BufferCommitmentCallback thresholdReachedCallback)
Method Detail

write

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

write

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

write

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

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

close

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

reset

void reset()

toString

@NotNull
public java.lang.String toString()
Overrides:
toString in class java.lang.Object

continueBuffering

private boolean continueBuffering(int numAdditionalBytes)
                           throws java.io.IOException
Throws:
java.io.IOException

forceOutputStream1

void forceOutputStream1()
                  throws java.io.IOException
Throws:
java.io.IOException

switchToOutputStream2

void switchToOutputStream2()
                     throws java.io.IOException
Throws:
java.io.IOException

flushBufferToStream

private void flushBufferToStream(java.io.OutputStream out)
                          throws java.io.IOException
Throws:
java.io.IOException

checkClosed

private void checkClosed()