
public abstract class OutputStream extends Object implements Closeable, Flushable
Most clients will use output streams that write data to the file system
(FileOutputStream), the network (Socket.getOutputStream()/URLConnection.getOutputStream()), or to an in-memory byte array
(ByteArrayOutputStream).
Use OutputStreamWriter to adapt a byte stream like this one into a
character stream.
Most clients should wrap their output stream with BufferedOutputStream. Callers that do only bulk writes may omit buffering.
FilterOutputStream, which delegates all calls to the target output
stream.
All output stream subclasses should override both write(int) and write(byte[],int,int). The
three argument overload is necessary for bulk access to the data. This is
much more efficient than byte-by-byte access.
| Constructor and Description |
|---|
OutputStream()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this stream.
|
void |
flush()
Flushes this stream.
|
void |
write(byte[] buffer)
Equivalent to
write(buffer, 0, buffer.length). |
void |
write(byte[] buffer,
int offset,
int count)
Writes
count bytes from the byte array buffer starting at
position offset to this stream. |
abstract void |
write(int oneByte)
Writes a single byte to this stream.
|
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - if an error occurs while closing this stream.public void flush()
throws IOException
flush in interface FlushableIOException - if an error occurs while flushing this stream.public void write(byte[] buffer)
throws IOException
write(buffer, 0, buffer.length).IOExceptionpublic void write(byte[] buffer,
int offset,
int count)
throws IOException
count bytes from the byte array buffer starting at
position offset to this stream.buffer - the buffer to be written.offset - the start position in buffer from where to get bytes.count - the number of bytes from buffer to write to this
stream.IOException - if an error occurs while writing to this stream.IndexOutOfBoundsException - if offset < 0 or count < 0, or if
offset + count is bigger than the length of
buffer.public abstract void write(int oneByte)
throws IOException
oneByte is written to the stream.oneByte - the byte to be written.IOException - if an error occurs while writing to this stream.Copyright © 2018. All rights reserved.