Package org.fusesource.hawtbuf

Examples of org.fusesource.hawtbuf.DataByteArrayInputStream


    }

    public static Properties stringToProperties(String str) throws IOException {
        Properties result = new Properties();
        if (str != null && str.length() > 0) {
            DataByteArrayInputStream dataIn = new DataByteArrayInputStream(str.getBytes());
            result.load(dataIn);
            dataIn.close();
        }
        return result;
    }
View Full Code Here


    public SUBSCRIBE decode(MQTTFrame frame) throws ProtocolException {
        assert(frame.buffers.length == 1);
        header(frame.header());

        DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]);
        QoS qos = qos();
        if(qos != QoS.AT_MOST_ONCE) {
            messageId = is.readShort();
        }
        ArrayList<Topic> list = new ArrayList<Topic>();
        while(is.available() > 0) {
            Topic topic = new Topic(MessageSupport.readUTF(is), QoS.values()[is.readByte()]);
            list.add(topic);
        }
        topics = list.toArray(new Topic[list.size()]);
        return this;
    }
View Full Code Here

    public UNSUBSCRIBE decode(MQTTFrame frame) throws ProtocolException {
        assert(frame.buffers.length == 1);
        header(frame.header());

        DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]);

        QoS qos = qos();
        if(qos != QoS.AT_MOST_ONCE) {
            messageId = is.readShort();
        }
        ArrayList<UTF8Buffer> list = new ArrayList<UTF8Buffer>();
        while(is.available() > 0) {
            list.add(MessageSupport.readUTF(is));
        }
        topics = list.toArray(new UTF8Buffer[list.size()]);
        return this;
    }
View Full Code Here

        return TYPE;
    }

    public SUBACK decode(MQTTFrame frame) throws ProtocolException {
        assert(frame.buffers.length == 1);
        DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]);
        messageId = is.readShort();
        grantedQos = is.readBuffer(is.available()).toByteArray();
        return this;
    }
View Full Code Here

        return TYPE;
    }

    public CONNECT decode(MQTTFrame frame) throws ProtocolException {
        assert(frame.buffers.length == 1);
        DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]);

        UTF8Buffer protocolName = MessageSupport.readUTF(is);
        if (V4_PROTOCOL_NAME.equals(protocolName)) {
            version = is.readByte() & 0xFF;
            if( version < 4 ) {
                throw new ProtocolException("Invalid CONNECT frame: protocol name/version mismatch");
            }
        } else if( V3_PROTOCOL_NAME.equals(protocolName) ) {
            version = is.readByte() & 0xFF;
            if( version != 3 ) {
                throw new ProtocolException("Invalid CONNECT frame: protocol name/version mismatch");
            }
        } else {
            throw new ProtocolException("Invalid CONNECT frame");
        }

        byte flags = is.readByte();
        boolean username_flag = (flags & 0x80) > 0;
        boolean password_flag = (flags & 0x40) > 0;
        willRetain = (flags & 0x20) > 0;
        willQos = (byte) ((flags & 0x18) >>> 3);
        boolean will_flag = (flags & 0x04) > 0;
        cleanSession = (flags & 0x02) > 0;

        keepAlive = is.readShort();
        clientId = MessageSupport.readUTF(is);
        if( clientId.length == 0 ) {
            clientId = null;
        }
        if(will_flag) {
View Full Code Here

    }

    public PUBREL decode(MQTTFrame frame) throws ProtocolException {
        assert(frame.buffers.length == 1);
        header(frame.header());
        DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]);
        messageId = is.readShort();
        return this;
    }
View Full Code Here

        abstract byte messageType();

        protected AckBase decode(MQTTFrame frame) throws ProtocolException {
            assert(frame.buffers.length == 1);
            DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]);
            messageId = is.readShort();
            return this;
        }
View Full Code Here

    public PUBLISH decode(MQTTFrame frame) throws ProtocolException {
        assert(frame.buffers.length == 1);
        header(frame.header());

        DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]);
        topicName = MessageSupport.readUTF(is);
       
        QoS qos = qos();
        if(qos != QoS.AT_MOST_ONCE) {
            messageId = is.readShort();
        }
        payload = is.readBuffer(is.available());
        if( payload == null ) {
            payload = new Buffer(0);
        }
        return this;
    }
View Full Code Here

                int freePageExtent = -1;
                if( storeFreePages ) {
                    if( recover ) {
                        Buffer header = new Buffer(512);
                        mappedFileFactory.getMemoryMappedFile().read(0, header);
                        DataByteArrayInputStream his = new DataByteArrayInputStream(header);

                        Buffer magic = new Buffer(HAWT_DB_PAGE_FILE_MAGIC.length());
                        his.readFully(magic.data, magic.offset, magic.length());
                        if( !magic.ascii().equals(HAWT_DB_PAGE_FILE_MAGIC)) {
                            throw new IOPagingException("File's magic does not match expected value");
                        }
                        freePageExtent = his.readInt();
                        headerSize = his.readInt();
                        pageSize = his.readShort();
                    } else {
                    }
                }

                pageFile = new HawtPageFile(mappedFileFactory.getMemoryMappedFile(), pageSize, headerSize, maxPages, storeFreePages);
View Full Code Here

                throw new RuntimeException(e);
            }
        }

        void decode(Buffer buffer) throws PagingException {
            DataByteArrayInputStream is = new DataByteArrayInputStream(buffer);
            int length = readFields(is);
            is.setPos((FILE_HEADER_SIZE / 2) - 8);
            long expectedChecksum = is.readLong();
            CRC32 checksum = new CRC32();
            checksum.update(buffer.data, 0, length);
            if (checksum.getValue() != expectedChecksum) {
                // Try the 2nd copy..
                is.setPos(FILE_HEADER_SIZE / 2);
                length = readFields(is);
                is.setPos(FILE_HEADER_SIZE - 8);
                expectedChecksum = is.readLong();
                checksum = new CRC32();
                checksum.update(buffer.data, 0, length);
                if (checksum.getValue() != expectedChecksum) {
                    throw new PagingException("file header corruption detected.");
                }
View Full Code Here

TOP

Related Classes of org.fusesource.hawtbuf.DataByteArrayInputStream

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.