Search in sources :

Example 41 with Buffer

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);
    }
}
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 42 with Buffer

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
    }
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) BufferEditor(org.fusesource.hawtbuf.BufferEditor)

Example 43 with Buffer

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

Example 44 with Buffer

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);
    }
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) Message(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message) CachedEncodingTrait(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.CachedEncodingTrait) IOException(java.io.IOException)

Example 45 with Buffer

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));
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

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