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
OutputStreams inside a single underlying OutputStream. The results can be
deserialized as equally many distinct InputStreams 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this instance.voidstart()Start a newOutputStream.voidstop()End the currentOutputStream.voidwrite(int ch) Methods inherited from class java.io.FilterOutputStream
flush, write, writeMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
OutputStreamWriter
Constructor.- Parameters:
output- the underlyingOutputStreamthat will carry nestedOutputStreams within it
-
-
Method Details
-
start
Start a newOutputStream.- Throws:
IOException- if this instance is closedIOException- if anOutputStreamis already started
-
stop
End the currentOutputStream. This flushes the underlying output. A newOutputStreamwill be created upon the next invocation ofstart().- Throws:
IOException- if this instance is closedIOException- if noOutputStreamis currently startedIOException- if the underlyingOutputStreamthrows an exception
-
close
Close this instance. Does nothing if already closed. If there anOutputStreamis already started when this method is invoked, it will be implicitly stopped.This ends the current
OutputStreamand closes the underlying output.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException- if an there is an error closing the underlyingOutputStream
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-