Search in sources :

Example 1 with ByteArrayOutputStream

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);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException) Deflater(java.util.zip.Deflater) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream)

Example 2 with ByteArrayOutputStream

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);
    }
}
Also used : ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream)

Example 3 with ByteArrayOutputStream

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();
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream)

Example 4 with ByteArrayOutputStream

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);
    }
}
Also used : ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream)

Example 5 with ByteArrayOutputStream

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());
    }
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)7 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)5 DataOutputStream (java.io.DataOutputStream)3 Buffer (org.fusesource.hawtbuf.Buffer)2 OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 Deflater (java.util.zip.Deflater)1