public class FIXBuilder
extends java.lang.Object
// Create a string for the topic
String topic = "messages";
// Create a builder with 1024 bytes of initial capacity,
// using the default 0x01 delimiter.
FIXBuilder builder = new FIXBuilder(1024, (byte)1);
// Example publishing loop reusing the builder.
for (int i = 1; 1 <= 100; ++i) {
// Add fields for message.
builder.append(0, "" + i);
builder.append(1, "Here's another field");
builder.append(2, "1234567890");
// Use the version of publish() that takes a byte array and
// length for the topic and payload.
client.publish(topic.getBytes(), 0, topic.length(),
builder.getBytes(), 0, builder.getSize());
// Reuse the builder for the next message by clearing it.
builder.clear();
}
Constructor and Description |
---|
FIXBuilder(int capacity,
byte fieldSeparator)
Initializes a new instance of the FIXBuilder class with the
specified capacity and field separator.
|
Modifier and Type | Method and Description |
---|---|
FIXBuilder |
append(int tag,
byte[] value)
Appends a tag and value pair to contained within a byte buffer to the FIX message.
|
FIXBuilder |
append(int tag,
byte[] value,
int offset,
int length)
Appends a tag and value pair contained within a byte buffer to the FIX message.
|
FIXBuilder |
append(int tag,
java.lang.String value)
Appends a tag and value pair to the FIX message.
|
void |
clear()
Clears self.
|
byte[] |
getBytes()
Returns the byte array containing the FIX message.
|
int |
getSize()
Returns the number of bytes in the byte array containing the FIX message.
|
public FIXBuilder(int capacity, byte fieldSeparator)
capacity
- The initial capacity of the builder.fieldSeparator
- The field separator byte.public void clear()
public int getSize()
public byte[] getBytes()
public FIXBuilder append(int tag, byte[] value, int offset, int length) throws CommandException
tag
- The integer FIX tag to append.value
- The byte buffer containing the FIX value to append.offset
- The starting location of the value inside the byte buffer.length
- The length of the value inside the byte buffer.java.lang.IllegalArgumentException
- If the tag argument is negative.CommandException
- Not thrown, throws IllegalArgumentException
public FIXBuilder append(int tag, byte[] value) throws CommandException
tag
- The integer FIX to append.value
- The byte buffer containing the FIX value to append.CommandException
- error occurred while appending the tag and value to the
message.public FIXBuilder append(int tag, java.lang.String value) throws CommandException
tag
- The integer FIX tag to append.value
- The FIX value for the tag to append. The value will be converted
to an ISO-8859-1 byte array for writing.java.lang.IllegalArgumentException
- If the tag argument is negative.CommandException
- If the tag or value argument is not convertible
to ISO-8859-1.