Search in sources :

Example 26 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class BaseDataStreamMarshaller method tightUnmarshalBuffer.

protected Buffer tightUnmarshalBuffer(DataByteArrayInputStream dataIn, BooleanStream bs) throws IOException {
    Buffer rc = null;
    if (bs.readBoolean()) {
        int size = dataIn.readInt();
        byte[] t = new byte[size];
        dataIn.readFully(t);
        return new Buffer(t, 0, size);
    }
    return rc;
}
Also used : UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer) Buffer(org.fusesource.hawtbuf.Buffer)

Example 27 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class ActiveMQStreamMessage method initializeReading.

private void initializeReading() throws OpenwireException {
    checkWriteOnlyBody();
    if (this.dataIn == null) {
        Buffer data = getContent();
        if (data == null) {
            data = new Buffer(new byte[] {}, 0, 0);
        }
        InputStream is = new ByteArrayInputStream(data);
        if (isCompressed()) {
            is = new InflaterInputStream(is);
            is = new BufferedInputStream(is);
        }
        this.dataIn = new DataInputStream(is);
    }
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteArrayInputStream(org.fusesource.hawtbuf.ByteArrayInputStream) ByteArrayInputStream(org.fusesource.hawtbuf.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InflaterInputStream(java.util.zip.InflaterInputStream)

Example 28 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class ActiveMQTextMessage method getText.

public String getText() throws OpenwireException {
    if (text == null && getContent() != null) {
        InputStream is = null;
        try {
            Buffer bodyAsBytes = getContent();
            if (bodyAsBytes != null) {
                is = new ByteArrayInputStream(bodyAsBytes);
                if (isCompressed()) {
                    is = new InflaterInputStream(is);
                }
                DataInputStream dataIn = new DataInputStream(is);
                text = MarshallingSupport.readUTF8(dataIn);
                dataIn.close();
                setContent(null);
                setCompressed(false);
            }
        } catch (IOException ioe) {
            throw new OpenwireException(ioe);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                // ignore
                }
            }
        }
    }
    return text;
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException) ByteArrayInputStream(org.fusesource.hawtbuf.ByteArrayInputStream) ByteArrayInputStream(org.fusesource.hawtbuf.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InflaterInputStream(java.util.zip.InflaterInputStream)

Example 29 with Buffer

use of org.fusesource.hawtbuf.Buffer in project activemq-artemis by apache.

the class AmqpSupport method toBuffer.

/**
 * Conversion from Java ByteBuffer to a HawtBuf buffer.
 *
 * @param data the ByteBuffer instance to convert.
 * @return a new HawtBuf buffer converted from the given ByteBuffer.
 */
public static Buffer toBuffer(ByteBuffer data) {
    if (data == null) {
        return null;
    }
    Buffer rc;
    if (data.isDirect()) {
        rc = new Buffer(data.remaining());
        data.get(rc.data);
    } else {
        rc = new Buffer(data);
        data.position(data.position() + data.remaining());
    }
    return rc;
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer)

Example 30 with Buffer

use of org.fusesource.hawtbuf.Buffer in project activemq-artemis by apache.

the class AmqpSupport method toBytes.

/**
 * Given a long value, convert it to a byte array for marshalling.
 *
 * @param value the value to convert.
 * @return a new byte array that holds the big endian value of the long.
 */
public static byte[] toBytes(long value) {
    Buffer buffer = new Buffer(8);
    buffer.bigEndianEditor().writeLong(value);
    return buffer.data;
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Buffer (org.fusesource.hawtbuf.Buffer)45 IOException (java.io.IOException)17 ByteBuffer (java.nio.ByteBuffer)10 Exchange (org.apache.camel.Exchange)9 Test (org.junit.Test)9 Transaction (org.fusesource.hawtdb.api.Transaction)8 UTF8Buffer (org.fusesource.hawtbuf.UTF8Buffer)6 SortedIndex (org.fusesource.hawtdb.api.SortedIndex)6 InflaterInputStream (java.util.zip.InflaterInputStream)5 ByteArrayInputStream (org.fusesource.hawtbuf.ByteArrayInputStream)5 BufferState (io.fabric8.dosgi.io.ProtocolCodec.BufferState)4 OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)3 DataStructure (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure)2 RandomAccessFile (java.io.RandomAccessFile)2 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)2 BufferEditor (org.fusesource.hawtbuf.BufferEditor)2 ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)2 DataByteArrayOutputStream (org.fusesource.hawtbuf.DataByteArrayOutputStream)2 Index (org.fusesource.hawtdb.api.Index)2 ObjectSerializationStrategy (io.fabric8.dosgi.api.ObjectSerializationStrategy)1