public class Writer
extends java.lang.Object
implements java.lang.AutoCloseable
Constructor and Description |
---|
Writer()
Default constructor.
|
Writer(java.nio.ByteBuffer buf)
Constructor for writing to a ByteBuffer.
|
Writer(java.nio.ByteBuffer buf,
byte[] userHeader)
Constructor for writing to a ByteBuffer with a user header.
|
Writer(java.nio.ByteBuffer buf,
int maxEventCount,
int maxBufferSize,
java.lang.String dictionary,
byte[] firstEvent)
Constructor with byte order.
|
Writer(java.nio.ByteOrder order,
int maxEventCount,
int maxBufferSize)
Constructor with byte order.
|
Writer(HeaderType hType,
java.nio.ByteOrder order,
int maxEventCount,
int maxBufferSize)
Constructor with byte order and header type.
|
Writer(HeaderType hType,
java.nio.ByteOrder order,
int maxEventCount,
int maxBufferSize,
java.lang.String dictionary,
byte[] firstEvent,
CompressionType compType,
boolean addTrailerIndex)
Constructor with byte order.
|
Writer(java.lang.String filename)
Constructor with filename.
|
Writer(java.lang.String filename,
java.nio.ByteOrder order,
int maxEventCount,
int maxBufferSize)
Constructor with filename and byte order.
|
Modifier and Type | Method and Description |
---|---|
void |
addEvent(byte[] buffer)
Add a byte array to the internal record.
|
void |
addEvent(byte[] buffer,
int offset,
int length)
Add a byte array to the internal record.
|
void |
addEvent(java.nio.ByteBuffer buffer)
Add a ByteBuffer to the internal record.
|
void |
addEvent(EvioBank bank)
Add an EvioBank to the internal record.
|
void |
addEvent(EvioNode node)
Add an EvioNode to the internal record.
|
boolean |
addTrailer()
Does this writer add a trailer to the end of the file/buffer?
|
void |
addTrailer(boolean add)
Set whether this writer adds a trailer to the end of the file/buffer.
|
boolean |
addTrailerWithIndex()
Does this writer add a trailer with a record index to the end of the file?
Or, if writing to a buffer, is a trailer added with no index?
|
void |
addTrailerWithIndex(boolean addTrailingIndex)
Set whether this writer adds a trailer with a record index to the end of the file.
|
void |
close()
Close opened file.
|
java.nio.ByteBuffer |
createHeader(byte[] userHeader)
Create and return a buffer containing a general file header
followed by the user header given in the argument.
|
java.nio.ByteBuffer |
createHeader(java.nio.ByteBuffer userHeader)
Create and return a buffer containing a general file header
followed by the user header given in the argument.
|
static java.nio.ByteBuffer |
createRecord(java.lang.String dictionary,
byte[] firstEvent,
java.nio.ByteOrder byteOrder,
FileHeader fileHeader,
RecordHeader recordHeader)
Create a buffer representation of a record
containing dictionary and/or first event.
|
java.nio.ByteBuffer |
getBuffer()
Get the buffer being written to.
|
java.nio.ByteOrder |
getByteOrder()
Get the file's byte order.
|
CompressionType |
getCompressionType()
Convenience method that gets compression type for the file being written.
|
FileHeader |
getFileHeader()
Get the file header.
|
void |
open(java.nio.ByteBuffer buf,
byte[] userHeader)
Specify a buffer and write first record header with given user header.
|
void |
open(java.nio.ByteBuffer buf,
byte[] userHdr,
int off,
int len)
Specify a buffer and write first record header with given user header.
|
void |
open(java.lang.String filename)
Open a new file and write file header with no user header.
|
void |
open(java.lang.String filename,
byte[] userHeader)
Open a file and write file header with given user header.
|
void |
reset()
Get this object ready for re-use.
|
Writer |
setCompressionType(CompressionType compression)
Convenience method that sets compression type for the file.
|
void |
writeRecord(RecordOutputStream record)
Appends the record to the file.
|
public Writer()
public Writer(java.nio.ByteOrder order, int maxEventCount, int maxBufferSize)
HeaderType.EVIO_FILE
).order
- byte order of written file. Little endian if null.maxEventCount
- max number of events a record can hold.
Value of O means use default (1M).maxBufferSize
- max number of uncompressed data bytes a record can hold.
Value of < 8MB results in default of 8MB.public Writer(HeaderType hType, java.nio.ByteOrder order, int maxEventCount, int maxBufferSize)
hType
- the type of the file. If set to HeaderType.HIPO_FILE
,
the header will be written with the first 4 bytes set to HIPO.order
- byte order of written file. Little endian if null.maxEventCount
- max number of events a record can hold.
Value of O means use default (1M).maxBufferSize
- max number of uncompressed data bytes a record can hold.
Value of < 8MB results in default of 8MB.public Writer(HeaderType hType, java.nio.ByteOrder order, int maxEventCount, int maxBufferSize, java.lang.String dictionary, byte[] firstEvent, CompressionType compType, boolean addTrailerIndex)
hType
- the type of the file. If set to HeaderType.HIPO_FILE
,
the header will be written with the first 4 bytes set to HIPO.order
- byte order of written file. Little endian if null.maxEventCount
- max number of events a record can hold.
Value of O means use default (1M).maxBufferSize
- max number of uncompressed data bytes a record can hold.
Value of < 8MB results in default of 8MB.dictionary
- string holding an evio format dictionary to be placed in userHeader.firstEvent
- byte array containing an evio event to be included in userHeader.
It must be in the same byte order as the order argument.compType
- type of data compression to use.addTrailerIndex
- if true, we add a record index to the trailer.public Writer(java.lang.String filename) throws java.io.IOException
open(String)
is called in this method and should not be called again.
File byte order is little endian.filename
- output file namejava.io.IOException
- if file cannot be found or IO error writing to filepublic Writer(java.lang.String filename, java.nio.ByteOrder order, int maxEventCount, int maxBufferSize) throws java.io.IOException
open(String)
is called in this method and should not be called again.
LZ4 compression.filename
- output file nameorder
- byte order of written file or null for default (little endian)maxEventCount
- max number of events a record can hold.
Value of O means use default (1M).maxBufferSize
- max number of uncompressed data bytes a record can hold.
Value of < 8MB results in default of 8MB.java.io.IOException
- if file cannot be found or IO error writing to filepublic Writer(java.nio.ByteBuffer buf) throws HipoException
buf
- buffer in to which to write events and/or records.HipoException
- if buf arg is null.public Writer(java.nio.ByteBuffer buf, byte[] userHeader) throws HipoException
buf
- buffer in to which to write events and/or records.userHeader
- array containing user header.HipoException
- if buf arg is null.public Writer(java.nio.ByteBuffer buf, int maxEventCount, int maxBufferSize, java.lang.String dictionary, byte[] firstEvent) throws HipoException
buf
- buffer in to which to write events and/or records.maxEventCount
- max number of events a record can hold.
Value of O means use default (1M).maxBufferSize
- max number of uncompressed data bytes a record can hold.
Value of < 8MB results in default of 8MB.dictionary
- string holding an evio format dictionary to be placed in userHeader.firstEvent
- byte array containing an evio event to be included in userHeader.
It must be in the same byte order as the order argument.HipoException
- if buf arg is null.public java.nio.ByteBuffer getBuffer()
public java.nio.ByteOrder getByteOrder()
public FileHeader getFileHeader()
public CompressionType getCompressionType()
public final Writer setCompressionType(CompressionType compression)
compression
- compression typepublic boolean addTrailer()
public void addTrailer(boolean add)
add
- if true, at the end of file/buffer, add an ending header (trailer)
with no index of records and no following data.
Update the file header to contain a file offset to the trailer.public boolean addTrailerWithIndex()
public void addTrailerWithIndex(boolean addTrailingIndex)
addTrailingIndex
- if true, at the end of file, add an ending header (trailer)
with an index of all records but with no following data.
Update the file header to contain a file offset to the trailer.
If true, and writing to a buffer, add a trailer with no index
to the end of the buffer.public final void open(java.lang.String filename) throws HipoException, java.io.IOException
filename
- output file nameHipoException
- if open already called without being followed by calling close.java.io.IOException
- if file cannot be found or IO error writing to filepublic final void open(java.lang.String filename, byte[] userHeader) throws HipoException, java.io.IOException
filename
- name of file to write to.userHeader
- byte array representing the optional user's header.
If this is null AND dictionary and/or first event are given,
the dictionary and/or first event will be placed in its
own record and written as the user header.HipoException
- filename arg is null, if constructor specified writing to a buffer,
or if open() was already called without being followed by reset().java.io.IOException
- if file cannot be found or IO error writing to filepublic final void open(java.nio.ByteBuffer buf, byte[] userHeader) throws HipoException
buf
- buffer to writer to.userHeader
- byte array representing the optional user's header.
Warning: this will not be used until first record is written!
So don't go changing it in the meantime!
If this is null AND dictionary and/or first event are given,
the dictionary and/or first event will be placed in its
own record and written as the user header of the first record's
header.HipoException
- buf arg is null, if constructor specified writing to a file,
or if open() was already called without being followed by reset().public final void open(java.nio.ByteBuffer buf, byte[] userHdr, int off, int len) throws HipoException
buf
- buffer to writer to.userHdr
- byte array representing the optional user's header.
Warning: this will not be used until first record is written!
So don't go changing it in the meantime!
If this is null AND dictionary and/or first event are given,
the dictionary and/or first event will be placed in its
own record and written as the user header of the first record's
header.off
- offset of valid data in userHdr.len
- length of valid data (bytes) in userHdr (starting at off).HipoException
- buf arg is null, if constructor specified writing to a file,
or if open() was already called without being followed by reset().public static java.nio.ByteBuffer createRecord(java.lang.String dictionary, byte[] firstEvent, java.nio.ByteOrder byteOrder, FileHeader fileHeader, RecordHeader recordHeader)
dictionary
- dictionary xml stringfirstEvent
- bytes representing evio eventbyteOrder
- byte order of returned byte arrayfileHeader
- file header to update with dictionary/first-event info (may be null).recordHeader
- record header to update with dictionary info (may be null).public java.nio.ByteBuffer createHeader(byte[] userHeader) throws HipoException
userHeader
- byte array containing a user-defined header, may be null.HipoException
- if writing to buffer.public java.nio.ByteBuffer createHeader(java.nio.ByteBuffer userHeader) throws HipoException
userHeader
- buffer containing a user-defined header which must be READY-TO-READ!HipoException
- if writing to buffer.public void writeRecord(RecordOutputStream record) throws java.io.IOException
record
- record objectjava.lang.IllegalArgumentException
- if arg's byte order is opposite to output endian.java.io.IOException
- if error writing to file.public void addEvent(byte[] buffer) throws java.io.IOException
buffer
- array to add to the file.java.io.IOException
- if cannot write to file.public void addEvent(byte[] buffer, int offset, int length) throws java.io.IOException
buffer
- array to add to the file.offset
- offset into array from which to start writing data.length
- number of bytes to write from array.java.io.IOException
- if cannot write to file.public void addEvent(java.nio.ByteBuffer buffer) throws java.io.IOException, HipoException
buffer
- array to add to the file.HipoException
- if buf arg's byte order is wrong.java.io.IOException
- if cannot write to file.public void addEvent(EvioBank bank) throws java.io.IOException
bank
- event to add to the file.java.io.IOException
- if cannot write to file.public void addEvent(EvioNode node) throws HipoException, java.io.IOException
node
- node to add to the file.HipoException
- if node does not correspond to a bank.java.io.IOException
- if cannot write to file.public void reset()
open(String)
.public void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
java.io.IOException
- if error writing to file