|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
org.gcube.contentmanagement.baselayer.streamutils.FinishingActionOutputStream
public class FinishingActionOutputStream
This class provites a generic wrapper for OutputStreams, which are decorated
with some action that should be performed when the end of the stream has been
reached, in other words, the stream is closed. For convenience, also the
functionality to count the number of written bytes has been implemented here,
so through this, the attached action can decide on the number of bytes that
have been written, what to do next.
There is an implementation for this available in the Jakarta Commons IO
classes, but since this was not enough work to implement here, it was
preferred not to include yet another dependency here - just use a similar
interface.
OutputStream
,
org.apache.commons.io.output.CountingOutputStream
Constructor Summary | |
---|---|
FinishingActionOutputStream(java.io.OutputStream wrappedStream,
FinishingAction action)
wrapps a stream with some action, that will be executed once, when the end of the stream has been reached, that is, the stream is closed. |
Method Summary | |
---|---|
void |
close()
|
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 |
void |
flush()
|
long |
getCount()
Returns the number of bytes written to 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 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 |
void |
write(byte[] b)
|
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FinishingActionOutputStream(java.io.OutputStream wrappedStream, FinishingAction action)
wrappedStream
- the stream from which the data is takenaction
- the action that should be executedMethod Detail |
---|
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.OutputStream
java.io.IOException
public void finish() throws java.io.IOException
finish
in interface FinishingActionStream
java.io.IOException
- if something goes wrongpublic void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public long getCount()
getCount
in interface FinishingActionStream
public long resetCount()
resetCount
in interface FinishingActionStream
0
public java.io.IOException exceptionBeforeFinishing()
exceptionBeforeFinishing
in interface FinishingActionStream
public void resetExceptionBeforeFinishing()
resetExceptionBeforeFinishing
in interface FinishingActionStream
public void incrementCount(long valueToAdd) throws java.io.IOException
incrementCount
in interface FinishingActionStream
valueToAdd
- the value to add to the counter
java.io.IOException
- if something goes wrongpublic FinishingAction getFinishingAction()
getFinishingAction
in interface FinishingActionStream
public void setFinishingAction(FinishingAction finishingAction)
setFinishingAction
in interface FinishingActionStream
finishingAction
- the actionpublic java.lang.Object getWrappedStream()
getWrappedStream
in interface FinishingActionStream
public void setWrappedStream(java.lang.Object wrappedStream)
setWrappedStream
in interface FinishingActionStream
wrappedStream
- the wrapped stream
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |