public class MappedBusWriter
extends java.lang.Object
Messages can either be message based or byte array based.
The typical usage is as follows:
// Construct a writer
MappedBusWriter writer = new MappedBusWriter("/tmp/test", 100000L, 32, true);
writer.open();
// A: write an object based message
PriceUpdate priceUpdate = new PriceUpdate();
writer.write(priceUpdate);
// B: write a byte array based message
byte[] buffer = new byte[32];
writer.write(buffer, 0, buffer.length);
// Close the writer
writer.close();
Constructor and Description |
---|
MappedBusWriter(java.lang.String fileName,
long fileSize,
int recordSize,
boolean append)
Constructs a new writer.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the writer.
|
void |
open()
Opens the writer.
|
void |
write(byte[] src,
int offset,
int length)
Writes a buffer of data.
|
void |
write(MappedBusMessage message)
Writes a message.
|
public MappedBusWriter(java.lang.String fileName, long fileSize, int recordSize, boolean append)
fileName
- the name of the memory mapped filefileSize
- the maximum size of the filerecordSize
- the maximum size of a record (excluding status flags and meta data)append
- whether to append to the file (will create a new file if false)public void open() throws java.io.IOException
java.io.IOException
- if there was an error opening the filepublic void write(MappedBusMessage message) throws java.io.EOFException
message
- the message object to writejava.io.EOFException
- in case the end of the file was reachedpublic void write(byte[] src, int offset, int length) throws java.io.EOFException
src
- the output bufferoffset
- the offset in the buffer of the first byte to writelength
- the length of the datajava.io.EOFException
- in case the end of the file was reachedpublic void close() throws java.io.IOException
java.io.IOException
- if there was an error closing the file