try
{
byte[] buf = new byte[1024];
BBEncoder bbenc = (BBEncoder) enc;
BytesMessage msg = session.createBytesMessage();
ByteBuffer slice = bbenc.buffer();
while (slice.hasRemaining())
{
int n = Math.min(buf.length, slice.remaining());
slice.get(buf, 0, n);
msg.writeBytes(buf, 0, n);