Package java.io
Class OutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Modified
- Direct Known Subclasses:
DummyOutputStream,PrintStream,SCIOutputStream,UARTOutputStream,UARTOutputStream,UARTOutputStream
public abstract class OutputStream extends Object implements Closeable, Flushable, Modified
A writable sink for bytes.Use
OutputStreamWriterto 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.Subclassing OutputStream
Subclasses that decorate another output stream should consider subclassingFilterOutputStream, which delegates all calls to the target output stream.All output stream subclasses should override both
write(int)andwrite(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.- See Also:
InputStream
-
-
Constructor Summary
Constructors Constructor Description OutputStream()Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) booleancheckError()Returns true if this writer has encountered and suppressed an error.voidclose()Closes this stream.voidflush()Flushes this stream.voidwrite(byte[] buffer)Equivalent towrite(buffer, 0, buffer.length).voidwrite(byte[] buffer, int offset, int count)Writescountbytes from the byte arraybufferstarting at positionoffsetto this stream.abstract voidwrite(int oneByte)Writes a single byte to this stream.
-
-
-
Method Detail
-
close
public void close() throws IOExceptionCloses this stream. Implementations of this method should free any resources used by the stream. This implementation does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an error occurs while closing this stream.
-
flush
public void flush() throws IOExceptionFlushes this stream. Implementations of this method should ensure that any buffered data is written out. This implementation does nothing.- Specified by:
flushin interfaceFlushable- Throws:
IOException- if an error occurs while flushing this stream.
-
write
public void write(byte[] buffer) throws IOExceptionEquivalent towrite(buffer, 0, buffer.length).- Parameters:
buffer- the buffer to be written.- Throws:
IOException- if an error occurs while writing to this stream.IndexOutOfBoundsException- ifoffset < 0orcount < 0, or ifoffset + countis bigger than the length ofbuffer.
-
write
public void write(byte[] buffer, int offset, int count) throws IOExceptionWritescountbytes from the byte arraybufferstarting at positionoffsetto this stream.- Parameters:
buffer- the buffer to be written.offset- the start position inbufferfrom where to get bytes.count- the number of bytes frombufferto write to this stream.- Throws:
IOException- if an error occurs while writing to this stream.IndexOutOfBoundsException- ifoffset < 0orcount < 0, or ifoffset + countis bigger than the length ofbuffer.
-
write
public abstract void write(int oneByte) throws IOExceptionWrites a single byte to this stream. Only the least significant byte of the integeroneByteis written to the stream.- Parameters:
oneByte- the byte to be written.- Throws:
IOException- if an error occurs while writing to this stream.
-
checkError
boolean checkError()
Returns true if this writer has encountered and suppressed an error. Used by PrintStreams as an alternative to checked exceptions.- Returns:
trueif error occurred.
-
-