Package org.fusesource.hawtbuf

Examples of org.fusesource.hawtbuf.Buffer


            boolean ascii = bs.readBoolean(); // ignored for now.
            int size = dataIn.readShort();
            if( size== 0 ) {
                return new UTF8Buffer("");
            } else {
                Buffer buffer = dataIn.readBuffer(size);
                return buffer.utf8();
            }
        } else {
            return null;
        }
    }
View Full Code Here


            dataOut.write(data.getData(), data.getOffset(), data.getLength());
        }
    }

    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;
    }
View Full Code Here

            dataOut.write(data.getData(), data.getOffset(), data.getLength());
        }
    }

    protected Buffer looseUnmarshalBuffer(DataByteArrayInputStream dataIn) throws IOException {
        Buffer rc = null;
        if (dataIn.readBoolean()) {
            int size = dataIn.readInt();
            byte[] t = new byte[size];
            dataIn.readFully(t);
            rc = new Buffer(t, 0, size);
        }
        return rc;
    }
View Full Code Here

            }

            @Override
            public void onTransportCommand(Object command) {
                try {
                    Buffer buffer;
                    if( command.getClass() == AmqpHeader.class ) {
                        AmqpHeader header = (AmqpHeader)command;
                        switch( header.getProtocolId() ) {
                            case 0:
                                break; // nothing to do..
View Full Code Here

        byte data[] = new byte[size];
        boolean done = false;
        while( !done && !hawtdispatchTransport.full() ) {
            int count = protonTransport.output(data, 0, size);
            if( count > 0 ) {
                hawtdispatchTransport.offer(new Buffer(data, 0, count));
            } else {
                done = true;
            }
        }
        if( !hawtdispatchTransport.full() ) {
View Full Code Here

    @Override
    protected Action initialDecodeAction() {
        return new Action() {
            public Object apply() throws IOException {
                Buffer magic = readBytes(8);
                if (magic != null) {
                    nextDecodeAction = readFrameSize;
                    return new AmqpHeader(magic);
                } else {
                    return null;
View Full Code Here


    private final Action readFrame(final int size) {
        return new Action() {
            public Object apply() throws IOException {
                Buffer frameData = readBytes(size);
                if (frameData != null) {
                    nextDecodeAction = readFrameSize;
                    return frameData;
                } else {
                    return null;
View Full Code Here

    });

    private Buffer buffer;

    public AmqpHeader(){
        this(new Buffer(new byte[]{
          'A', 'M', 'Q', 'P', 0, 1, 0, 0
        }));
    }
View Full Code Here

        //        // same
        //        if (!cacheEnabled && ((DataStructure)command).isMarshallAware()) {
        //            ma = (MarshallAware)command;
        //        }

        Buffer sequence = null;
        // if( ma!=null ) {
        // sequence = ma.getCachedMarshalledForm(this);
        // }

        if (sequence == null) {

            int size = 1;
            if (command != null) {

                DataStructure c = (DataStructure) command;
                byte type = c.getDataStructureType();
                DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[type & 0xFF];
                if (dsm == null) {
                    throw new IOException("Unknown data type: " + type);
                }
                if (tightEncodingEnabled) {

                    BooleanStream bs = new BooleanStream();
                    size += dsm.tightMarshal1(this, c, bs);
                    size += bs.marshalledSize();

                    bytesOut.restart(size);
                    if (!sizePrefixDisabled) {
                        bytesOut.writeInt(size);
                    }
                    bytesOut.writeByte(type);
                    bs.marshal(bytesOut);
                    dsm.tightMarshal2(this, c, bytesOut, bs);
                    sequence = bytesOut.toBuffer();

                } else {
                    bytesOut.restart();
                    if (!sizePrefixDisabled) {
                        bytesOut.writeInt(0); // we don't know the final size
                        // yet but write this here for
                        // now.
                    }
                    bytesOut.writeByte(type);
                    dsm.looseMarshal(this, c, bytesOut);
                    sequence = bytesOut.toBuffer();

                    if (!sizePrefixDisabled) {
                        size = sequence.getLength() - 4;
                        int pos = sequence.offset;
                        sequence.offset = 0;
                        BufferEditor.big(sequence).writeInt(size);
                        sequence.offset = pos;
                    }
View Full Code Here

                looseOut.writeByte(type);
                dsm.looseMarshal(this, c, looseOut);

                if (!sizePrefixDisabled) {
                    Buffer sequence = bytesOut.toBuffer();
                    dataOut.writeInt(sequence.getLength());
                    dataOut.write(sequence.getData(), sequence.getOffset(), sequence.getLength());
                }

            }

        } else {
View Full Code Here

TOP

Related Classes of org.fusesource.hawtbuf.Buffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.