当前位置: 首页>>代码示例>>Java>>正文


Java ChannelBufferInputStream类代码示例

本文整理汇总了Java中com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream的典型用法代码示例。如果您正苦于以下问题:Java ChannelBufferInputStream类的具体用法?Java ChannelBufferInputStream怎么用?Java ChannelBufferInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelBufferInputStream类属于com.alibaba.dubbo.remoting.buffer包,在下文中一共展示了ChannelBufferInputStream类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {
//        InputStream input = new ChannelBufferInputStream(buffer);
//        return decodeData(channel, getSerialization(channel).deserialize(channel.getUrl(), input));

        // modified by lishen
        InputStream input = new ChannelBufferInputStream(buffer);
        ObjectInput objectInput = getSerialization(channel).deserialize(channel.getUrl(), input);
        Object object = decodeData(channel, objectInput);
        if (objectInput instanceof Cleanable) {
            ((Cleanable) objectInput).cleanup();
        }
        return object;
    }
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:14,代码来源:TransportCodec.java

示例2: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {
    InputStream input = new ChannelBufferInputStream(buffer);
    ObjectInput objectInput = getSerialization(channel).deserialize(channel.getUrl(), input);
    Object object = decodeData(channel, objectInput);
    if(objectInput instanceof Cleanable){
        Cleanable cleanable = (Cleanable)objectInput;
        cleanable.cleanup();
    }
    return object;
}
 
开发者ID:AllenRay,项目名称:dubbo-ex,代码行数:11,代码来源:TransportCodec.java

示例3: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException {
    // check magic number.
    if (readable > 0 && header[0] != MAGIC_HIGH 
            || readable > 1 && header[1] != MAGIC_LOW) {
        int length = header.length;
        if (header.length < readable) {
            header = Bytes.copyOf(header, readable);
            buffer.readBytes(header, length, readable - length);
        }
        for (int i = 1; i < header.length - 1; i ++) {
            if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) {
                buffer.readerIndex(buffer.readerIndex() - header.length + i);
                header = Bytes.copyOf(header, i);
                break;
            }
        }
        return super.decode(channel, buffer, readable, header);
    }
    // check length.
    if (readable < HEADER_LENGTH) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    // get data length.
    int len = Bytes.bytes2int(header, 12);
    checkPayload(channel, len);

    int tt = len + HEADER_LENGTH;
    if( readable < tt ) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    // limit input stream.
    ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len);

    try {
        return decodeBody(channel, is, header);
    } finally {
        if (is.available() > 0) {
            try {
                if (logger.isWarnEnabled()) {
                    logger.warn("Skip input stream " + is.available());
                }
                StreamUtils.skipUnusedStream(is);
            } catch (IOException e) {
                logger.warn(e.getMessage(), e);
            }
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:51,代码来源:ExchangeCodec.java

示例4: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {
    InputStream input = new ChannelBufferInputStream(buffer);
    return decodeData(channel, getSerialization(channel).deserialize(channel.getUrl(), input));
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:5,代码来源:TransportCodec.java

示例5: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException {
    // check magic number.
    if (readable > 0 && header[0] != MAGIC_HIGH 
            || readable > 1 && header[1] != MAGIC_LOW) {
        int length = header.length;
        if (header.length < readable) {
            header = Bytes.copyOf(header, readable);
            buffer.readBytes(header, length, readable - length);
        }
        for (int i = 1; i < header.length - 1; i ++) {
            if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) {//这里究竟是个什么意思
                buffer.readerIndex(buffer.readerIndex() - header.length + i);
                header = Bytes.copyOf(header, i);
                break;
            }
        }
        return super.decode(channel, buffer, readable, header);
    }
    // check length.
    if (readable < HEADER_LENGTH) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    // get data length.
    int len = Bytes.bytes2int(header, 12);
    checkPayload(channel, len);

    int tt = len + HEADER_LENGTH;
    if( readable < tt ) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    // limit input stream.
    ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len);

    try {
        return decodeBody(channel, is, header);
    } finally {
        if (is.available() > 0) {
            try {
                if (logger.isWarnEnabled()) {
                    logger.warn("Skip input stream " + is.available());
                }
                StreamUtils.skipUnusedStream(is);
            } catch (IOException e) {
                logger.warn(e.getMessage(), e);
            }
        }
    }
}
 
开发者ID:spccold,项目名称:dubbo-comments,代码行数:51,代码来源:ExchangeCodec.java

示例6: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException {
    // 如果header的前两个字节不是魔数的话
    if (readable > 0 && header[0] != MAGIC_HIGH 
            || readable > 1 && header[1] != MAGIC_LOW) {
        int length = header.length;
        if (header.length < readable) {
            header = Bytes.copyOf(header, readable);
            buffer.readBytes(header, length, readable - length);
        }
        //逐步检查buffer中是否有魔数开头的header,有的话就直接读取到header数组中
        for (int i = 1; i < header.length - 1; i ++) {
            if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) {
                buffer.readerIndex(buffer.readerIndex() - header.length + i);
                header = Bytes.copyOf(header, i);
                break;
            }
        }
        //处理父类telnet的解码
        return super.decode(channel, buffer, readable, header);
    }
    // 数据不全(头部不完整)
    if (readable < HEADER_LENGTH) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    //获取body长度,检查8M最大限制
    int len = Bytes.bytes2int(header, 12);
    checkPayload(channel, len);

    int tt = len + HEADER_LENGTH;
    // 数据不全(body不完整)
    if( readable < tt ) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    // limit input stream.
    ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len);

    try {
        return decodeBody(channel, is, header);
    } finally {
        if (is.available() > 0) {
            try {
                if (logger.isWarnEnabled()) {
                    logger.warn("Skip input stream " + is.available());
                }
                StreamUtils.skipUnusedStream(is);
            } catch (IOException e) {
                logger.warn(e.getMessage(), e);
            }
        }
    }
}
 
开发者ID:DoubleSmile,项目名称:dubbo-learning,代码行数:54,代码来源:ExchangeCodec.java

示例7: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException {
	// check magic number.
	if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) {
		int length = header.length;
		if (header.length < readable) {
			header = Bytes.copyOf(header, readable);
			buffer.readBytes(header, length, readable - length);
		}
		for (int i = 1; i < header.length - 1; i++) {
			if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) {
				buffer.readerIndex(buffer.readerIndex() - header.length + i);
				header = Bytes.copyOf(header, i);
				break;
			}
		}
		return super.decode(channel, buffer, readable, header);
	}
	// check length.
	if (readable < HEADER_LENGTH) {
		return DecodeResult.NEED_MORE_INPUT;
	}

	// get data length.
	int len = Bytes.bytes2int(header, 12);
	checkPayload(channel, len);

	int tt = len + HEADER_LENGTH;
	if (readable < tt) {
		return DecodeResult.NEED_MORE_INPUT;
	}

	// limit input stream.
	ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len);

	try {
		return decodeBody(channel, is, header);
	} finally {
		if (is.available() > 0) {
			try {
				if (log.isWarnEnabled()) {
					log.warn("Skip input stream " + is.available());
				}
				StreamUtils.skipUnusedStream(is);
			} catch (IOException e) {
				log.warn(e.getMessage(), e);
			}
		}
	}
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:50,代码来源:ExchangeCodec.java

示例8: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException {
    // check magic number.
    if (readable > 0 && header[0] != MAGIC_HIGH
            || readable > 1 && header[1] != MAGIC_LOW) {
        int length = header.length;
        if (header.length < readable) {
            header = Bytes.copyOf(header, readable);
            buffer.readBytes(header, length, readable - length);
        }
        for (int i = 1; i < header.length - 1; i++) {
            if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) {
                buffer.readerIndex(buffer.readerIndex() - header.length + i);
                header = Bytes.copyOf(header, i);
                break;
            }
        }
        return super.decode(channel, buffer, readable, header);
    }
    // check length.
    if (readable < HEADER_LENGTH) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    // get data length.
    int len = Bytes.bytes2int(header, 12);
    checkPayload(channel, len);

    int tt = len + HEADER_LENGTH;
    if (readable < tt) {
        return DecodeResult.NEED_MORE_INPUT;
    }

    // limit input stream.
    ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len);

    try {
        return decodeBody(channel, is, header);
    } finally {
        if (is.available() > 0) {
            try {
                if (logger.isWarnEnabled()) {
                    logger.warn("Skip input stream " + is.available());
                }
                StreamUtils.skipUnusedStream(is);
            } catch (IOException e) {
                logger.warn(e.getMessage(), e);
            }
        }
    }
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:51,代码来源:ExchangeCodec.java

示例9: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {

        int available = buffer.readableBytes();

        if (available < MESSAGE_SHORTEST_LENGTH) {

            return DecodeResult.NEED_MORE_INPUT;

        } else {

            TIOStreamTransport transport = new TIOStreamTransport(new ChannelBufferInputStream(buffer));

            TBinaryProtocol protocol = new TBinaryProtocol(transport);

            short magic;
            int messageLength;

            try {
//                protocol.readI32(); // skip the first message length
                byte[] bytes = new byte[4];
                transport.read(bytes, 0, 4);
                magic = protocol.readI16();
                messageLength = protocol.readI32();

            } catch (TException e) {
                throw new IOException(e.getMessage(), e);
            }

            if (MAGIC != magic) {
                throw new IOException(
                        new StringBuilder(32)
                                .append("Unknown magic code ")
                                .append(magic)
                                .toString());
            }

            if (available < messageLength) {
                return DecodeResult.NEED_MORE_INPUT;
            }

            return decode(protocol);

        }

    }
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:46,代码来源:ThriftCodec.java

示例10: decode

import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream; //导入依赖的package包/类
public Object decode( Channel channel, ChannelBuffer buffer ) throws IOException {

        int available = buffer.readableBytes();

        if ( available < MESSAGE_SHORTEST_LENGTH ) {

            return DecodeResult.NEED_MORE_INPUT;

        } else {

            TIOStreamTransport transport = new TIOStreamTransport( new ChannelBufferInputStream(buffer));

            TBinaryProtocol protocol = new TBinaryProtocol( transport );

            short magic;
            int messageLength;

            try{
//                protocol.readI32(); // skip the first message length
                byte[] bytes = new byte[4];
                transport.read( bytes, 0, 4 );
                magic = protocol.readI16();
                messageLength = protocol.readI32();

            } catch ( TException e ) {
                throw new IOException( e.getMessage(), e );
            }

            if ( MAGIC != magic ) {
                throw new IOException(
                        new StringBuilder( 32 )
                                .append( "Unknown magic code " )
                                .append( magic )
                                .toString() );
            }

            if ( available < messageLength ) { return  DecodeResult.NEED_MORE_INPUT; }

            return decode( protocol );

        }

    }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:44,代码来源:ThriftCodec.java


注:本文中的com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。