org.gcube.contentmanagement.baselayer.streamutils
Interface FinishingActionStream

All Known Subinterfaces:
CountExceedsStream
All Known Implementing Classes:
CountExceedsActionInputStream, CountExceedsActionOutputStream, FinishingActionInputStream, FinishingActionOutputStream

public interface FinishingActionStream

Defines a common interface for streams, that are able to perform an action when the end of the stream has been reached.

Unfortunately, there has been no common interface for arbitrary streams in Java until Java 5 (when the Closeable interface has been introduced), and even worse, InputStream and OutputStream are classes, which have not been defined as or implemented against any interface, such that subclasses need to extend them directly -and there is no possibility, e.g. to inherit functionality provided in an (abstract) class. Otherwise much of the operations defined in here could have been implemented in such an abstract class, such that it could be used directly in FinishingActionOutputStream as well as FinishingActionInputStream.


Method Summary
 java.io.IOException exceptionBeforeFinishing()
          Captures any error/exception/throwable or exception that occured right before executing the finishing action, in particular any IOException that occured when closing the stream.
By this, the action can decide how to deal with this exception.
 void finish()
          closes the wrapped stream and then executes the action, that has been defined to take place at the end of the stream
 long getCount()
          Returns the number of bytes written to or read fromor skipped on the stream.
 FinishingAction getFinishingAction()
          Retruns the assigned finishing action
 java.lang.Object getWrappedStream()
          Returns the wrapped stream on which the stream operates
 void incrementCount(long valueToAdd)
          Increments the value of count by the given value.
 long resetCount()
          Resets the number of bytes written / read to zero, to start again counting.
 void resetExceptionBeforeFinishing()
          Resets any exception that has been captured before executing the finishing action, such that it will not be thrown after finishing action was performed.
 void setFinishingAction(FinishingAction finishingAction)
          Sets the action that should be performed for finishing processing of the stream
 void setWrappedStream(java.lang.Object wrappedStream)
          Sets the wrapped stream on which the stream operates
 

Method Detail

finish

void finish()
            throws java.io.IOException
closes the wrapped stream and then executes the action, that has been defined to take place at the end of the stream

Throws:
java.io.IOException - if something goes wrong

getCount

long getCount()
Returns the number of bytes written to or read fromor skipped on the stream.

This is the actual number counted, if a stream supports marking - in other words, if mark(int) and reset has been used, some bytes might get be counted more than once!

Returns:
number of bytes written since beginning or last reset

resetCount

long resetCount()
Resets the number of bytes written / read to zero, to start again counting.

Returns:
the previous content of the counter, that has now been set to 0

incrementCount

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

Parameters:
valueToAdd - the value to add to the counter
Throws:
java.io.IOException - if something goes wrong

exceptionBeforeFinishing

java.io.IOException exceptionBeforeFinishing()
Captures any error/exception/throwable or exception that occured right before executing the finishing action, in particular any IOException that occured when closing the stream.
By this, the action can decide how to deal with this exception. If this error is not reset, it will be thrown after the action has been performed.

Returns:
the exception, that has been captured

resetExceptionBeforeFinishing

void resetExceptionBeforeFinishing()
Resets any exception that has been captured before executing the finishing action, such that it will not be thrown after finishing action was performed.


getFinishingAction

FinishingAction getFinishingAction()
Retruns the assigned finishing action

Returns:
the action

setFinishingAction

void setFinishingAction(FinishingAction finishingAction)
Sets the action that should be performed for finishing processing of the stream

Parameters:
finishingAction - the action

getWrappedStream

java.lang.Object getWrappedStream()
Returns the wrapped stream on which the stream operates

Returns:
the wrapped stream

setWrappedStream

void setWrappedStream(java.lang.Object wrappedStream)
Sets the wrapped stream on which the stream operates

Parameters:
wrappedStream - the wrapped stream