use of org.fusesource.hawtbuf.ByteArrayOutputStream in project fabric8 by jboss-fuse.
the class ActiveMQBytesMessage method initializeWriting.
private void initializeWriting() throws OpenwireException {
checkReadOnlyBody();
if (this.dataOut == null) {
this.bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
if (Settings.enable_compression()) {
// we are compressed.
try {
os.write(new byte[4]);
} catch (IOException e) {
throw new OpenwireException(e);
}
length = 0;
compressed = true;
final Deflater deflater = new Deflater(Deflater.BEST_SPEED);
os = new FilterOutputStream(new DeflaterOutputStream(os, deflater)) {
public void write(byte[] arg0) throws IOException {
length += arg0.length;
out.write(arg0);
}
public void write(byte[] arg0, int arg1, int arg2) throws IOException {
length += arg2;
out.write(arg0, arg1, arg2);
}
public void write(int arg0) throws IOException {
length++;
out.write(arg0);
}
@Override
public void close() throws IOException {
super.close();
deflater.end();
}
};
}
this.dataOut = new DataOutputStream(os);
}
}
use of org.fusesource.hawtbuf.ByteArrayOutputStream in project fabric8 by jboss-fuse.
the class ActiveMQMapMessage method storeContent.
private void storeContent() {
try {
if (getContent() == null && !map.isEmpty()) {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
if (Settings.enable_compression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
MarshallingSupport.marshalPrimitiveMap(map, dataOut);
dataOut.close();
setContent(bytesOut.toBuffer());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.fusesource.hawtbuf.ByteArrayOutputStream in project fabric8 by jboss-fuse.
the class Message method beforeMarshall.
public void beforeMarshall(OpenWireFormat wireFormat) throws IOException {
// Need to marshal the properties.
if (marshalledProperties == null && properties != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(baos);
MarshallingSupport.marshalPrimitiveMap(properties, os);
os.close();
marshalledProperties = baos.toBuffer();
}
}
use of org.fusesource.hawtbuf.ByteArrayOutputStream in project fabric8 by jboss-fuse.
the class ActiveMQStreamMessage method initializeWriting.
private void initializeWriting() throws OpenwireException {
checkReadOnlyBody();
if (this.dataOut == null) {
this.bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
if (Settings.enable_compression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
this.dataOut = new DataOutputStream(os);
}
}
use of org.fusesource.hawtbuf.ByteArrayOutputStream in project fabric8 by jboss-fuse.
the class ActiveMQTextMessage method beforeMarshall.
public void beforeMarshall(OpenWireFormat wireFormat) throws IOException {
super.beforeMarshall(wireFormat);
Buffer content = getContent();
if (content == null && text != null) {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
if (Settings.enable_compression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
MarshallingSupport.writeUTF8(dataOut, this.text);
dataOut.close();
setContent(bytesOut.toBuffer());
}
}
Aggregations