org.gcube.contentmanagement.baselayer.streamutils
Class CountExceedsActionOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.gcube.contentmanagement.baselayer.streamutils.FinishingActionOutputStream
          extended by org.gcube.contentmanagement.baselayer.streamutils.CountExceedsActionOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, CountExceedsStream, FinishingActionStream

public class CountExceedsActionOutputStream
extends FinishingActionOutputStream
implements CountExceedsStream

This class defines an FinishingActionStreamOutputStream, where in addition, also an Action is triggered everytime the count of written bytes exceeds a defined value.


Constructor Summary
CountExceedsActionOutputStream(java.io.OutputStream wrappedStream, FinishingAction action, long countThreshold, FinishingAction exceedsThresholdAction)
          Constructs a new stream
 
Method Summary
 long getCountThreshold()
          Returns the defined threshold of the count
 FinishingAction getExceedsAction()
          Returns the action that will be performed to finish
 void incrementCount(long valueToAdd)
          Increments the value of count by the given value.
 void performExceedsAction()
          Performs the action for the event of exceeding the defined count
 void setCountThreshold(long countThreshold)
          Sets the threshold on which the action should happen
 void setExceedsAction(FinishingAction exceedsAction)
          Sets the action that should be finished when the count is exceeded
 
Methods inherited from class org.gcube.contentmanagement.baselayer.streamutils.FinishingActionOutputStream
close, exceptionBeforeFinishing, finish, flush, getCount, getFinishingAction, getWrappedStream, resetCount, resetExceptionBeforeFinishing, setFinishingAction, setWrappedStream, write, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gcube.contentmanagement.baselayer.streamutils.FinishingActionStream
exceptionBeforeFinishing, finish, getCount, getFinishingAction, getWrappedStream, resetCount, resetExceptionBeforeFinishing, setFinishingAction, setWrappedStream
 

Constructor Detail

CountExceedsActionOutputStream

public CountExceedsActionOutputStream(java.io.OutputStream wrappedStream,
                                      FinishingAction action,
                                      long countThreshold,
                                      FinishingAction exceedsThresholdAction)
Constructs a new stream

Parameters:
wrappedStream - the stream on which the new stream will act as a wrapper
action - the action that should be performed if the end of the stream is reached
countThreshold - the threshold
exceedsThresholdAction - the action that should be performed if the threshold is exceeded of the stream is reached
Method Detail

incrementCount

public void incrementCount(long valueToAdd)
                    throws java.io.IOException
Increments the value of count by the given value.

Specified by:
incrementCount in interface FinishingActionStream
Overrides:
incrementCount in class FinishingActionOutputStream
Parameters:
valueToAdd - the value to add to the counter
Throws:
java.io.IOException - if something goes wrong

performExceedsAction

public void performExceedsAction()
                          throws java.io.IOException
Performs the action for the event of exceeding the defined count

Specified by:
performExceedsAction in interface CountExceedsStream
Throws:
java.io.IOException - if something goes wrong on the underlying stream

getCountThreshold

public long getCountThreshold()
Returns the defined threshold of the count

Specified by:
getCountThreshold in interface CountExceedsStream
Returns:
the threshold

setCountThreshold

public void setCountThreshold(long countThreshold)
Sets the threshold on which the action should happen

Specified by:
setCountThreshold in interface CountExceedsStream
Parameters:
countThreshold - the threshold

getExceedsAction

public FinishingAction getExceedsAction()
Returns the action that will be performed to finish

Specified by:
getExceedsAction in interface CountExceedsStream
Returns:
the action

setExceedsAction

public void setExceedsAction(FinishingAction exceedsAction)
Sets the action that should be finished when the count is exceeded

Specified by:
setExceedsAction in interface CountExceedsStream
Parameters:
exceedsAction - the action