Package com.globalmentor.io
Class InputStreamDecorator<I extends InputStream>
java.lang.Object
java.io.InputStream
com.globalmentor.io.InputStreamDecorator<I>
- Type Parameters:
I
- The type of input stream being decorated.
- All Implemented Interfaces:
Disposable
,Closeable
,AutoCloseable
- Direct Known Subclasses:
CaptureInputStream
,FixedLengthInputStream
,TempFileInputStream
Wraps an existing input stream. The decorated input stream is released when this stream is closed. This decorator provides convenience methods
beforeClose()
and afterClose()
called before and after the stream is closed, respectively.- Author:
- Garret Wilson
-
Constructor Summary
ConstructorsConstructorDescriptionInputStreamDecorator
(I inputStream) Decorates the given input stream, automatically callingdispose()
when closed.InputStreamDecorator
(I inputStream, boolean autoDispose) Decorates the given input stream. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Called after the stream is successfully closed.int
protected void
Called before the stream is closed.void
close()
Closes this input stream and releases any system resources associated with the stream.void
close
(boolean closeDecoratedStream) Closes this input stream and releases any system resources associated with the stream.void
dispose()
Uninitializes the object.protected void
finalize()
protected I
void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) void
reset()
long
skip
(long n)
-
Constructor Details
-
InputStreamDecorator
Decorates the given input stream, automatically callingdispose()
when closed.- Parameters:
inputStream
- The input stream to decorate.- Throws:
NullPointerException
- if the given stream isnull
.
-
InputStreamDecorator
Decorates the given input stream.- Parameters:
inputStream
- The input stream to decorate.autoDispose
- Whether the stream should be automatically disposed when closed.- Throws:
NullPointerException
- if the given stream isnull
.
-
-
Method Details
-
getInputStream
- Returns:
- The input stream being decorated, or
null
if it has been released after this stream was closed.
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
beforeClose
Called before the stream is closed.- Throws:
IOException
- if an I/O error occurs.
-
afterClose
Called after the stream is successfully closed.- Throws:
IOException
- if an I/O error occurs.
-
close
Closes this input stream and releases any system resources associated with the stream. A closed stream cannot perform output operations and cannot be reopened. If auto-dispose is enabled,dispose()
will be called if closing is successful.- Parameters:
closeDecoratedStream
- Whether the decorated stream should also be closed.- Throws:
IOException
- if an I/O error occurs.- See Also:
-
close
Closes this input stream and releases any system resources associated with the stream. A closed stream cannot perform output operations and cannot be reopened.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- if an I/O error occurs.- See Also:
-
dispose
public void dispose()Uninitializes the object. After calling this method, the object should not be used further. This method can be called multiple times without danger. All exceptions should be caught and dealt with in this method. Child classes must call the parent class version.- Specified by:
dispose
in interfaceDisposable
- Implementation Specification:
- This version closes the input stream and releases it, if still available.
-
finalize
-