A ByteArrayOutputStream implementation optimized for writing binary serialized data (e.g. Protocol Buffers).
Tries to avoid excessive memory allocations and array resizing by using an Array of Byte Arrays to represent the data. Supports directly appending Byte Arrays (zero-copy), writing length prefixed data, optimized writing of ASCII and UTF-8 strings without going through a java.io.Writer.
Value parameters
- BufferSize
-
The size of each buffer
- CompactThresholdSize
-
If writing length prefixed data we have a gap then compact the array if the written data is less than this amount
- InitialArrayCapacity
-
The initial capacity of the internal arrays
- MinUsefulBufferSize
-
If we are splicing data keep using the existing buffer if there is at least this much space in it
- SpliceThresholdSize
-
If writing a Byte Array that is over this length then splice it in. If it's under this length then just write it to our buffers
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Appendableclass OutputStreamtrait Flushabletrait Closeabletrait AutoCloseableclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Appendable Implementation
Appendable Implementation
Attributes
Appendable Implementation
Appendable Implementation
Attributes
Appendable Implementation
Appendable Implementation
Attributes
How many bytes are available in the current buffer
How many bytes are available in the current buffer
Attributes
Public accessor for tests
Public accessor for tests
Attributes
Ensure that there are at least size bytes available in the current buffer (or point to a new buffer).
Ensure that there are at least size bytes available in the current buffer (or point to a new buffer).
Attributes
This is for writing data that needs to have it's length prefixed when the prefixed length is variable. e.g. When write Protocol Buffers length delimited fields the length is a varint.
This is for writing data that needs to have it's length prefixed when the prefixed length is variable. e.g. When write Protocol Buffers length delimited fields the length is a varint.
This method takes the maximum prefix size we expect to write, a function that performs the writing the data, and a function that takes the number of bytes written via writeData and performs the length prefix write. If the length prefix write is less than the maxPrefixSize parameter then the array will either be compacted or split into two.
Attributes
Remove or Skip over the bytes at the starting index to length.
Remove or Skip over the bytes at the starting index to length.
These are expected to be contiguous bytes in one of the buffers. The buffer will be looked up based on the start index and then data will either be compacted or spliced around based on how much data comes after the skipped bytes
Attributes
Directly use this byte array (zero-copy). If there are bytes left in our current buffer to make it useful then we will splice this into our current array by saving the current array, saving this array, and then using the rest of the original array as our current buffer with updated start/offset/length
Directly use this byte array (zero-copy). If there are bytes left in our current buffer to make it useful then we will splice this into our current array by saving the current array, saving this array, and then using the rest of the original array as our current buffer with updated start/offset/length
Attributes
Create a byte array out of the current data
Create a byte array out of the current data
Attributes
OutputStream Implementation
OutputStream Implementation
Attributes
OutputStream Implementation
OutputStream Implementation
Attributes
- Definition Classes
-
OutputStream
OutputStream Implementation
OutputStream Implementation
Attributes
- Definition Classes
-
OutputStream
Optimized for when we know the characters are ASCII
Optimized for when we know the characters are ASCII
Attributes
Write the current data in the buffer to an OutputStream
Write the current data in the buffer to an OutputStream
Attributes
Returns the number of bytes written
Returns the number of bytes written
Attributes
Returns the number of bytes written
Returns the number of bytes written