public interface Output extends Appendable, Closeable, Flushable
Output is an Appendable with extra methods to append ByteBuffer and byte[].
An Output is a stateful object, it can be opened and closed.
An Output instance can create OutputStream or Writer based on itself.
Note the behavior differences between an Output and an Appendable: when a char sequence is null, nothing will be appended to the Output while a literal null will be appended to the Appendable
Depending on implementation Output might be or not be thread safe.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Output.Adaptors |
| Modifier and Type | Method and Description |
|---|---|
Output |
append(byte b)
Appends a byte to this
Output. |
Output |
append(byte[] bytes)
Appends a byte array to this
Output. |
Output |
append(byte[] bytes,
int start,
int end)
Appends a subsequence of the specified byte array to this Output.
|
Output |
append(ByteBuffer buffer)
Appends the specified buffer into this Appendable.
|
Output |
append(char c)
Appends the specified character to this Output.
|
Output |
append(CharSequence csq)
Appends the specified character sequence to this Output.
|
Output |
append(CharSequence csq,
int start,
int end)
Appends a subsequence of the specified character sequence to this Output.
|
OutputStream |
asOutputStream()
Create an
OutputStream based on this Output instance. |
Writer |
asWriter()
Create an
Writer based on this Output instance. |
void |
close()
Close this
Output instance. |
void |
flush()
Flushes the output.
|
void |
open()
Prepare this
Output instance for appending. |
void open()
Prepare this Output instance for appending. If any append method is called before calling open(), then open() will be called implicitly before appending happens.
void close()
Close this Output instance. Call to any append method after the Output is closed will result in IllegalStateException
close in interface AutoCloseableclose in interface Closeablevoid flush()
Flushes the output. If the output has saved any characters from the various append() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.
If the intended destination of this output is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
Output append(CharSequence csq)
Appends the specified character sequence to this Output.
Depending on which class implements the character sequence csq, the entire sequence may not be appended. For instance, if csq is a CharBuffer then the subsequence to append is defined by the buffer’s position and limit.
append in interface Appendablecsq - The character sequence to append. If csq is null, then nothing will be appendedOutput append(CharSequence csq, int start, int end)
Appends a subsequence of the specified character sequence to this Output.
An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation
out.append(csq.subSequence(start, end)) append in interface Appendablecsq - The character sequence from which a subsequence will be appended. If csq is null, then nothing will be appended.start - The index of the first character in the subsequenceend - The index of the character following the last character in the subsequenceIndexOutOfBoundsException - If start or end are negative, start is greater than end, or end is greater than csq.length()Output append(char c)
Appends the specified character to this Output.
append in interface Appendablec - The character to appendOutput append(byte[] bytes)
Appends a byte array to this Output.
bytes - The byte array will be appended.OutputOutput append(byte[] bytes, int start, int end)
Appends a subsequence of the specified byte array to this Output.
An invocation of this method of the form out.append(bytes, start, end) when bytes is not null, behaves in exactly the same way as the invocation
out.append(csq.subSequence(start, end)) bytes - The byte array from which a subsequence will be appended. If bytes is null, then nothing will be appended.start - The index of the first character in the subsequenceend - The index of the character following the last character in the subsequenceIndexOutOfBoundsException - If start or end are negative, start is greater than end, or end is greater than csq.length()Output append(byte b)
Appends a byte to this Output.
b - A byte will be appended.Output.Output append(ByteBuffer buffer)
Appends the specified buffer into this Appendable.
buffer - The buffer to append.OutputStream asOutputStream()
Create an OutputStream based on this Output instance.
Calling to this method before calling to any other method including asOutputStream() itself will result in IllegalStateException.
OutputStream reference backed by this Output.Writer asWriter()
Create an Writer based on this Output instance.
Calling to this method before calling to any other method including asOutputStream() itself will result in IllegalStateException.
Writer reference backed by this Output.Copyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.