public abstract class OutputStream extends AutoCloseable
flush()
method to be called before closing the stream, to ensure all data is
actually written through.
This abstract class does not provide a fully working implementation, so it needs to be subclassed, and at least the
write(int)
method needs to be overridden. Overriding some of the non-abstract methods is also often advised,
since it might result in higher efficiency.InputStream
Constructor and Description |
---|
OutputStream() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this stream, freeing any resources associated with it and then calling the closedListener, if one is set.
|
protected abstract void |
doClose()
This is an internal method, implemented by subclasses to close any resources associated with the stream.
|
void |
flush()
Flushes this stream.
|
ClosedListener |
getClosedListener() |
void |
setClosedListener(ClosedListener closedListener)
A ClosedListener provides a way to be notified when the stream is closed.
|
void |
write(byte[] buffer)
Writes the entire contents of the byte array
buffer to this stream. |
void |
write(byte[] buffer,
int offset,
int length)
Writes
count bytes from the byte array buffer starting at position offset to this
stream. |
void |
write(ByteArrayRange byteArrayRange) |
abstract void |
write(int oneByte)
Writes a single byte to this stream.
|
void |
writeLatin1EncodedString(java.lang.String s)
Write the string, assumed to contain only Latin1 characters (Unicode low 256 characters), to the stream.
|
void |
writeUtf8EncodedString(java.lang.String s)
Write the string to the stream using UTF-8 encoding.
|
public void write(byte[] buffer)
buffer
to this stream.buffer
- the buffer to be writtenIOException
- if an error occurs while writing to this streampublic void write(byte[] buffer, int offset, int length)
count
bytes from the byte array buffer
starting at position offset
to this
stream.buffer
- the buffer to be writtenoffset
- the start position in buffer
from where to get byteslength
- the number of bytes from buffer
to write to this streamIOException
- if an error occurs while writing to this streampublic void write(ByteArrayRange byteArrayRange)
public abstract void write(int oneByte)
oneByte
is written to
the stream.oneByte
- the byte to be written.java.io.IOException
- if an error occurs while writing to this stream.public void writeLatin1EncodedString(java.lang.String s)
s
- string to writepublic void flush()
IOException
- if an error occurs while flushing this streampublic void writeUtf8EncodedString(java.lang.String s)
s
- string to writepublic final void close()
close
in interface java.lang.AutoCloseable
close
in class AutoCloseable
IOException
- if an error occurs while closing this stream.protected abstract void doClose()
IOException
- if an error occurs while closing this stream.@Nullable public ClosedListener getClosedListener()
public void setClosedListener(@Nullable ClosedListener closedListener)
closedListener
-