use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class ActiveMQBytesMessage method initializeReading.
private void initializeReading() throws OpenwireException {
checkWriteOnlyBody();
if (dataIn == null) {
Buffer data = getContent();
if (data == null) {
data = new Buffer(new byte[] {}, 0, 0);
}
InputStream is = new ByteArrayInputStream(data);
if (isCompressed()) {
// we are compressed.
try {
DataInputStream dis = new DataInputStream(is);
length = dis.readInt();
dis.close();
} catch (IOException e) {
throw new OpenwireException(e);
}
is = new InflaterInputStream(is);
} else {
length = data.getLength();
}
dataIn = new DataInputStream(is);
}
}
use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class ActiveMQBytesMessage method storeContent.
private void storeContent() {
try {
if (dataOut != null) {
dataOut.close();
Buffer bs = bytesOut.toBuffer();
if (compressed) {
int pos = bs.offset;
bs.offset = 0;
BufferEditor e = BufferEditor.big(bs);
e.writeInt(length);
bs.offset = pos;
}
setContent(bs);
bytesOut = null;
dataOut = null;
}
} catch (IOException ioe) {
// TODO verify
throw new RuntimeException(ioe.getMessage(), ioe);
// RuntimeException
}
}
use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class ActiveMQObjectMessage method storeContent.
public void storeContent() {
Buffer bodyAsBytes = getContent();
if (bodyAsBytes == null && object != null) {
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
if (Settings.enable_compression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
ObjectOutputStream objOut = new ObjectOutputStream(dataOut);
objOut.writeObject(object);
objOut.flush();
objOut.reset();
objOut.close();
setContent(bytesOut.toBuffer());
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage(), ioe);
}
}
}
use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class OpenWireFormat method looseMarshalNestedObject.
public void looseMarshalNestedObject(DataStructure o, DataByteArrayOutputStream dataOut) throws IOException {
dataOut.writeBoolean(o != null);
if (o != null) {
if (o instanceof Message) {
if (!isTightEncodingEnabled() && !isCacheEnabled()) {
CachedEncodingTrait encoding = ((Message) o).getCachedEncoding();
if (encoding != null && !encoding.tight() && encoding.version() == getVersion()) {
Buffer buffer = encoding.buffer();
dataOut.write(buffer.data, buffer.offset + 4, buffer.length() - 4);
return;
}
}
}
byte type = o.getDataStructureType();
dataOut.writeByte(type);
DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[type & 0xFF];
if (dsm == null) {
throw new IOException("Unknown data type: " + type);
}
dsm.looseMarshal(this, o, dataOut);
}
}
use of org.fusesource.hawtbuf.Buffer in project hawtjournal by fusesource.
the class JournalTest method testSyncAndCallReplicator.
@Test
public void testSyncAndCallReplicator() throws Exception {
final int iterations = 3;
final CountDownLatch writeLatch = new CountDownLatch(1);
ReplicationTarget replicator = new ReplicationTarget() {
public void replicate(Location startLocation, Buffer data, boolean sync) {
if (startLocation.getDataFileId() == 1 && startLocation.getOffset() == 0) {
writeLatch.countDown();
}
}
};
journal.setReplicationTarget(replicator);
for (int i = 0; i < iterations; i++) {
journal.write(ByteBuffer.wrap(new String("DATA" + i).getBytes("UTF-8")), false);
}
journal.sync();
assertTrue(writeLatch.await(5, TimeUnit.SECONDS));
}
Aggregations