Package org.dellroad.stuff.io
Class OutputStreamWriter
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.dellroad.stuff.io.OutputStreamWriter
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Serializes zero or more
OutputStream
s inside a single underlying OutputStream
. The results can be
deserialized as equally many distinct InputStream
s on the other end using an InputStreamReader
.
Each OutputStream
may contain an arbitrary amount of data.
To use this class, invoke start()
to start a new OutputStream
, write to it by writing to this
class normally, and then use stop()
to close the current OutputStream
. A new, subsequent OutputStream
is created by invoking start()
again.
Each OutputStream
written in this way will be read as distinct InputStream
by the
InputStreamReader
at the other end.
Instances of this class are thread safe.
- See Also:
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this instance.void
start()
Start a newOutputStream
.void
stop()
End the currentOutputStream
.void
write
(int ch) Methods inherited from class java.io.FilterOutputStream
flush, write, write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
OutputStreamWriter
Constructor.- Parameters:
output
- the underlyingOutputStream
that will carry nestedOutputStream
s within it
-
-
Method Details
-
start
Start a newOutputStream
.- Throws:
IOException
- if this instance is closedIOException
- if anOutputStream
is already started
-
stop
End the currentOutputStream
. This flushes the underlying output. A newOutputStream
will be created upon the next invocation ofstart()
.- Throws:
IOException
- if this instance is closedIOException
- if noOutputStream
is currently startedIOException
- if the underlyingOutputStream
throws an exception
-
close
Close this instance. Does nothing if already closed. If there anOutputStream
is already started when this method is invoked, it will be implicitly stopped.This ends the current
OutputStream
and closes the underlying output.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
- if an there is an error closing the underlyingOutputStream
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-