final class FMByteArrayOutputStream extends OutputStream with Appendable
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.
- Alphabetic
- By Inheritance
- FMByteArrayOutputStream
- Appendable
- OutputStream
- Flushable
- Closeable
- AutoCloseable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
FMByteArrayOutputStream(InitialArrayCapacity: Int = ..., BufferSize: Int = ..., MinUsefulBufferSize: Int = ..., CompactThresholdSize: Int = ..., SpliceThresholdSize: Int = ...)
- InitialArrayCapacity
The initial capacity of the internal arrays
- BufferSize
The size of each buffer
- MinUsefulBufferSize
If we are splicing data keep using the existing buffer if there is at least this much space in it
- CompactThresholdSize
If writing length prefixed data we have a gap then compact the array if the written data is less than this amount
- 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
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
append(str: CharSequence, start: Int, end: Int): FMByteArrayOutputStream.this.type
Appendable Implementation
Appendable Implementation
- Definition Classes
- FMByteArrayOutputStream → Appendable
-
def
append(str: CharSequence): FMByteArrayOutputStream.this.type
Appendable Implementation
Appendable Implementation
- Definition Classes
- FMByteArrayOutputStream → Appendable
-
def
append(ch: Char): FMByteArrayOutputStream.this.type
Appendable Implementation
Appendable Implementation
- Definition Classes
- FMByteArrayOutputStream → Appendable
- def appendDoubleAsString(value: Double): Unit
- def appendFloatAsString(value: Float): Unit
- def appendIntAsString(value: Int): Unit
- def appendLongAsString(value: Long): Unit
-
final
def
array: Array[Byte]
- Annotations
- @inline()
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
available: Int
How many bytes are available in the current buffer
How many bytes are available in the current buffer
- Annotations
- @inline()
-
final
def
bufferCount: Int
Public accessor for tests
Public accessor for tests
- Annotations
- @inline()
-
def
check(): Unit
- Annotations
- @elidable( elidable.ASSERTION )
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
close(): Unit
- Definition Classes
- OutputStream → Closeable → AutoCloseable
- Annotations
- @throws( classOf[java.io.IOException] )
-
def
countBytes(f: ⇒ Unit): Int
- Annotations
- @inline()
-
def
debug(msg: String): Unit
- Annotations
- @elidable( elidable.FINE )
-
def
debugInfo: String
- Annotations
- @elidable( elidable.FINE )
-
def
dumpOnAssert(f: ⇒ Unit): Unit
- Annotations
- @elidable( elidable.ASSERTION )
-
def
ensureAvailable(size: Int): Unit
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).
- Annotations
- @inline()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flush(): Unit
- Definition Classes
- OutputStream → Flushable
- Annotations
- @throws( classOf[java.io.IOException] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
length: Int
- Annotations
- @inline()
-
def
lengthPrefixed(maxPrefixSize: Int)(writeData: ⇒ Unit)(writePrefix: (Int) ⇒ Unit): Unit
This is for writing data that needs to have it's length prefixed when the prefixed length is variable.
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.
- Annotations
- @inline()
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
final
def
offset: Int
- Annotations
- @inline()
- def offsetPlusPlus: Int
-
final
def
offset_=(v: Int): Unit
- Annotations
- @inline()
- def reset(): Unit
- final def shiftArray(arr: Array[Boolean], start: Int, len: Int, shift: Int): Unit
- final def shiftArray(arr: Array[Int], start: Int, len: Int, shift: Int): Unit
- final def shiftArray(arr: Array[Byte], start: Int, len: Int, shift: Int): Unit
- final def shiftArray(arr: Array[Array[Byte]], start: Int, len: Int, shift: Int): Unit
-
def
skipBytes(globalIdx: Int, len: Int): Unit
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
-
def
splice(bytes: Array[Byte], off: Int, len: Int): Unit
Directly use this byte array (zero-copy).
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
-
final
def
start: Int
- Annotations
- @inline()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toByteArray: Array[Byte]
Create a byte array out of the current data
-
def
toString(): String
- Definition Classes
- AnyRef → Any
- def totalSize: Int
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
- def write(str: String, start: Int, len: Int): Unit
- def write(str: String): Unit
-
def
write(bytes: Array[Byte], off: Int, len: Int): Unit
OutputStream Implementation
OutputStream Implementation
- Definition Classes
- FMByteArrayOutputStream → OutputStream
-
def
write(bytes: Array[Byte]): Unit
OutputStream Implementation
OutputStream Implementation
- Definition Classes
- FMByteArrayOutputStream → OutputStream
-
def
write(b: Int): Unit
OutputStream Implementation
OutputStream Implementation
- Definition Classes
- FMByteArrayOutputStream → OutputStream
-
def
writeASCII(str: String): Unit
Optimized for when we know the characters are ASCII
-
def
writeTo(os: OutputStream): Unit
Write the current data in the buffer to an OutputStream
-
def
writeUTF8Bytes(str: String, start: Int, len: Int): Int
Returns the number of bytes written
-
def
writeUTF8Bytes(str: String): Int
Returns the number of bytes written