public byte[] toByteArray() {
    return os.toByteArray();
  }
This is required while writing the byte stream.

@param offsetCount Number of offsets to appended in this byte stream.
@param size Size of the byte stream (excluding DSCODE, length int and the offsets.)
@return size of each offset
geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java