public class RecordOutputStream
extends java.lang.Object
RECORD STRUCTURE:
Uncompressed Compressed
+----------------------------------+ +----------------------------------+
| General Record Header | | General Record Header |
+----------------------------------+ +----------------------------------+
+----------------------------------+ ---------> +----------------------------------+
| Index Array | | Compressed Data |
+----------------------------------+ | Record |
| |
+----------------------------------+ | |
| User Header | | ----------------|
| (Optional) | | | Pad 3 |
| ----------------| +----------------------------------+
| | Pad 1 | ^
+----------------------------------+ /
/
+----------------------------------+ /
| Data Record | /
| | /
| ----------------| /
| | Pad 2 | /
+----------------------------------+
GENERAL RECORD HEADER STRUCTURE ( see RecordHeader.java )
+----------------------------------+
1 | Record Length | // 32bit words, inclusive
+----------------------------------+
2 + Record Number |
+----------------------------------+
3 + Header Length | // 14 (words)
+----------------------------------+
4 + Event (Index) Count |
+----------------------------------+
5 + Index Array Length | // bytes
+-----------------------+---------+
6 + Bit Info | Version | // version (8 bits)
+-----------------------+----------+
7 + User Header Length | // bytes
+----------------------------------+
8 + Magic Number | // 0xc0da0100
+----------------------------------+
9 + Uncompressed Data Length | // bytes
+------+---------------------------+
10 + CT | Data Length Compressed | // CT = compression type (4 bits)
+----------------------------------+
11 + General Register 1 | // UID 1st (64 bits)
+-- --+
12 + |
+----------------------------------+
13 + General Register 2 | // UID 2nd (64 bits)
+-- --+
14 + |
+----------------------------------+
Constructor and Description |
---|
RecordOutputStream()
Default, no-arg constructor.
|
RecordOutputStream(java.nio.ByteBuffer buffer,
int maxEventCount,
CompressionType compressionType,
HeaderType hType)
Constructor with arguments.
|
RecordOutputStream(java.nio.ByteOrder order,
int maxEventCount,
int maxBufferSize,
CompressionType compressionType)
Constructor with arguments.
|
RecordOutputStream(java.nio.ByteOrder order,
int maxEventCount,
int maxBufferSize,
CompressionType compressionType,
HeaderType hType)
Constructor with arguments.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addEvent(byte[] event)
Adds an event's ByteBuffer into the record.
|
boolean |
addEvent(byte[] event,
int position,
int eventLen)
Adds an event's data into the record.
|
boolean |
addEvent(byte[] event,
int position,
int eventLen,
int extraDataLen)
Adds an event's data into the record.
|
boolean |
addEvent(java.nio.ByteBuffer event)
Adds an event's ByteBuffer into the record.
|
boolean |
addEvent(java.nio.ByteBuffer event,
int extraDataLen)
Adds an event's ByteBuffer into the record.
|
boolean |
addEvent(EvioBank event)
Adds an event's ByteBuffer into the record.
|
boolean |
addEvent(EvioBank event,
int extraDataLen)
Adds an event's ByteBuffer into the record.
|
boolean |
addEvent(EvioNode node)
Adds an event's ByteBuffer into the record.
|
boolean |
addEvent(EvioNode node,
int extraDataLen)
Adds an event's ByteBuffer into the record.
|
void |
build()
Builds the record.
|
void |
build(java.nio.ByteBuffer userHeader)
Builds the record.
|
java.nio.ByteBuffer |
getBinaryBuffer()
Get the internal ByteBuffer used to construct binary representation of this record.
|
java.nio.ByteOrder |
getByteOrder()
Get the byte order of the record to be built.
|
int |
getEventCount()
Get the number of events written so far into the buffer
|
RecordHeader |
getHeader()
Get the general header of this record.
|
int |
getInternalBufferCapacity()
Get the capacity of the internal buffer in bytes.
|
int |
getMaxEventCount()
Get the max number of events that can be accepted into this record.
|
int |
getUncompressedSize()
Get the current uncompressed size of the record in bytes.
|
int |
getUserBufferSize()
Get the number of initially available bytes to be written into in the user-given buffer,
that goes from position to limit.
|
boolean |
hasUserProvidedBuffer()
Was the internal buffer provided by the user?
|
boolean |
oneTooMany()
Does adding one more event exceed the event count limit?
|
void |
reset()
Reset internal buffers.
|
boolean |
roomForEvent(int length)
Is there room in this record's memory for an additional event
of the given length in bytes (length NOT including accompanying index).
|
void |
setBuffer(java.nio.ByteBuffer buf)
Reset internal buffers and set the buffer in which to build this record.
|
void |
setStartingBufferPosition(int pos)
Set the starting position of the user-given buffer being written into.
|
void |
transferDataForReading(RecordOutputStream rec)
Copy the contents of the arg into this object and get data buffer ready for reading.
|
public RecordOutputStream()
public RecordOutputStream(java.nio.ByteOrder order, int maxEventCount, int maxBufferSize, CompressionType compressionType)
order
- byte order of built record byte arrays.maxEventCount
- max number of events this record can hold.
Value <= O means use default (1M).maxBufferSize
- max number of uncompressed data bytes this record can hold.
Value of < 8MB results in default of 8MB.compressionType
- type of data compression to do (0=none, 1=lz4 fast, 2=lz4 best, 3=gzip).public RecordOutputStream(java.nio.ByteOrder order, int maxEventCount, int maxBufferSize, CompressionType compressionType, HeaderType hType)
order
- byte order of built record byte arrays.maxEventCount
- max number of events this record can hold.
Value <= O means use default (1M).maxBufferSize
- max number of uncompressed data bytes this record can hold.
Value of < 8MB results in default of 8MB.compressionType
- type of data compression to do (0=none, 1=lz4 fast, 2=lz4 best, 3=gzip).hType
- type of record header to use.public RecordOutputStream(java.nio.ByteBuffer buffer, int maxEventCount, CompressionType compressionType, HeaderType hType)
buffer
- buffer in which to put constructed (and compressed) binary record.
Must have position and limit set to accept new data.maxEventCount
- max number of events this record can hold.
Value <= O means use default (1M).compressionType
- type of data compression to do (0=none, 1=lz4 fast, 2=lz4 best, 3=gzip).hType
- type of record header to use.public void setBuffer(java.nio.ByteBuffer buf)
getBinaryBuffer()
.buf
- buffer in which to build this record.public void transferDataForReading(RecordOutputStream rec) throws HipoException
rec
- object to copy, must be read to read.HipoException
- if we cannot replace internal buffer if it needs to be
expanded since it was provided by the user.public int getMaxEventCount()
public int getUserBufferSize()
public int getUncompressedSize()
public int getInternalBufferCapacity()
public RecordHeader getHeader()
public int getEventCount()
public java.nio.ByteBuffer getBinaryBuffer()
public boolean hasUserProvidedBuffer()
public java.nio.ByteOrder getByteOrder()
public boolean roomForEvent(int length)
length
- length of data to add in bytestrue
if room in record, else false
.public boolean oneTooMany()
true
if one more event exceeds count limit, else false
.public boolean addEvent(byte[] event)
The byte order of event must match the byte order given in constructor!
event
- event's byte array.public boolean addEvent(byte[] event, int position, int eventLen)
The byte order of event must match the byte order given in constructor!
event
- event's byte array.position
- offset into event byte array from which to begin reading.eventLen
- number of bytes from byte array to add.public boolean addEvent(byte[] event, int position, int eventLen, int extraDataLen)
If a single event is too large for the internal buffers, more memory is allocated. On the other hand, if the buffer was provided by the user, then obviously the buffer cannot be expanded and false is returned.
The byte order of event must match the byte order given in constructor!
event
- event's byte array.position
- offset into event byte array from which to begin reading.eventLen
- number of bytes from byte array to add.extraDataLen
- additional data bytes to follow event (e.g. trailer length).public boolean addEvent(java.nio.ByteBuffer event)
The byte order of event must match the byte order given in constructor!
event
- event's ByteBuffer object.public boolean addEvent(java.nio.ByteBuffer event, int extraDataLen)
If a single event is too large for the internal buffers, more memory is allocated. On the other hand, if the buffer was provided by the user, then obviously the buffer cannot be expanded and false is returned.
The byte order of event must match the byte order given in constructor!
event
- event's ByteBuffer object.extraDataLen
- additional data bytes to follow event (e.g. trailer length).public boolean addEvent(EvioNode node) throws HipoException
The byte order of event must match the byte order given in constructor! This method is not thread-safe with respect to the node as it's backing ByteBuffer's limit and position may be concurrently changed.
node
- event's EvioNode objectHipoException
- if node does not correspond to a bank.public boolean addEvent(EvioNode node, int extraDataLen) throws HipoException
If a single event is too large for the internal buffers, more memory is allocated. On the other hand, if the buffer was provided by the user, then obviously the buffer cannot be expanded and false is returned.
The byte order of event must match the byte order given in constructor! This method is not thread-safe with respect to the node as it's backing ByteBuffer's limit and position may be concurrently changed.
node
- event's EvioNode objectextraDataLen
- additional data bytes to follow event (e.g. trailer length).HipoException
- if node does not correspond to a bank.public boolean addEvent(EvioBank event)
The byte order of event must match the byte order given in constructor!
event
- event's EvioBank object.public boolean addEvent(EvioBank event, int extraDataLen)
If a single event is too large for the internal buffers, more memory is allocated. On the other hand, if the buffer was provided by the user, then obviously the buffer cannot be expanded and false is returned.
The byte order of event must match the byte order given in constructor!
event
- event's EvioBank object.extraDataLen
- additional data bytes to follow event (e.g. trailer length).public void reset()
public void setStartingBufferPosition(int pos)
pos
- position in buffer to start writing.public void build()
getBinaryBuffer()
has its position and limit set for reading.public void build(java.nio.ByteBuffer userHeader)
userHeader
- user's ByteBuffer which must be READY-TO-READ!