Class WrappedOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
This output stream is used like any normal output stream. The protocol is introduced by the WrappedOutputStream and does not need to be known by the user of this class. However, for those that are interested, the method is described below.
The output stream writes the requested bytes as packets of binary information. The packet consists of a header and payload. The header is two bytes of a single unsigned short (written in network order) that specifies the length of bytes in the payload. A header value of 0 indicates that the stream is "closed".
Note: For this wrapped output stream to be used,
the application must call close()
to end the output.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default buffer size (1024).protected byte[]
Buffer.protected DataOutputStream
Data output stream.protected int
Buffer position.Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorsConstructorDescriptionWrappedOutputStream
(OutputStream stream) Constructs a wrapper for the given output stream.WrappedOutputStream
(OutputStream stream, int bufferSize) Constructs a wrapper for the given output stream with the given buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the output stream.void
flush()
Flushes the output buffer, writing all bytes currently in the buffer to the output.void
flush0()
Flushes the output buffer, writing all bytes currently in the buffer to the output.void
write
(byte[] b, int offset, int length) Writes an array of bytes to the output.void
write
(int b) Writes a single byte to the output.Methods inherited from class java.io.FilterOutputStream
write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size (1024).- See Also:
-
fBuffer
protected byte[] fBufferBuffer. -
fPosition
protected int fPositionBuffer position. -
fDataOutputStream
Data output stream. This stream is used to output the block sizes into the data stream that are read by the WrappedInputStream.Note: The data output stream is only used for writing the byte count for performance reasons. We avoid the method indirection for writing the byte data.
-
-
Constructor Details
-
WrappedOutputStream
Constructs a wrapper for the given output stream. -
WrappedOutputStream
Constructs a wrapper for the given output stream with the given buffer size.
-
-
Method Details
-
write
Writes a single byte to the output.Note: Single bytes written to the output stream will be buffered
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
Writes an array of bytes to the output.- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
flush
Flushes the output buffer, writing all bytes currently in the buffer to the output.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterOutputStream
- Throws:
IOException
-
close
Closes the output stream. This method must be called when done writing all data to the output stream.Note: This method does not close the actual output stream, only makes the input stream see the stream closed. Do not write bytes after closing the output stream.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
-
flush0
Flushes the output buffer, writing all bytes currently in the buffer to the output. This method does not call the flush() method of the output stream; it merely writes the remaining bytes in the buffer.- Throws:
IOException
-