本文整理汇总了Java中org.apache.mina.filter.codec.ProtocolDecoderOutput.write方法的典型用法代码示例。如果您正苦于以下问题:Java ProtocolDecoderOutput.write方法的具体用法?Java ProtocolDecoderOutput.write怎么用?Java ProtocolDecoderOutput.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.filter.codec.ProtocolDecoderOutput
的用法示例。
在下文中一共展示了ProtocolDecoderOutput.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws Exception
{
@SuppressWarnings("unchecked")
LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer =
( LdapMessageContainer<MessageDecorator<? extends Message>> )
session.getAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR );
if ( session.containsAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR ) )
{
int maxPDUSize = ( Integer ) session.getAttribute( LdapDecoder.MAX_PDU_SIZE_ATTR );
messageContainer.setMaxPDUSize( maxPDUSize );
}
List<Message> decodedMessages = new ArrayList<>();
ByteBuffer buf = in.buf();
decode( buf, messageContainer, decodedMessages );
for ( Message message : decodedMessages )
{
out.write( message );
}
}
示例2: processWriteResult
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
private boolean processWriteResult ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
try
{
final int operationId = data.getInt ();
final int errorCode = data.getUnsignedShort ();
final String errorMessage = decodeString ( session, data );
out.write ( new WriteResult ( operationId, errorCode, errorMessage ) );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
return true;
}
示例3: processDataUpdate
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
private boolean processDataUpdate ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
final int count = data.getUnsignedShort ();
final List<DataUpdate.Entry> entries = new ArrayList<DataUpdate.Entry> ( count );
for ( int i = 0; i < count; i++ )
{
entries.add ( decodeDataUpdateEntry ( data, session ) );
}
out.write ( new DataUpdate ( entries ) );
return true;
}
示例4: processBrowseAdded
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
private boolean processBrowseAdded ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
final int count = data.getUnsignedShort ();
final List<BrowseAdded.Entry> entries = new ArrayList<BrowseAdded.Entry> ( count );
for ( int i = 0; i < count; i++ )
{
entries.add ( decodeBrowserAddEntry ( data, session ) );
}
out.write ( new BrowseAdded ( entries ) );
return true;
}
示例5: processHello
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
private boolean processHello ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
final byte version = data.get ();
if ( version != 0x01 )
{
throw new ProtocolCodecException ( String.format ( "Protocol version %s is unsupported", version ) );
}
final short nodeId = data.getShort ();
final EnumSet<Hello.Features> features = data.getEnumSetShort ( Hello.Features.class );
out.write ( new Hello ( nodeId, features ) );
return true;
}
示例6: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
if (in.prefixedDataAvailable(2)) {
short length = in.getShort();//获取包长
byte[] bytes = new byte[length];
in.get(bytes);
byte[] msgidBytes = new byte[Constants.COMMAND_LENGTH];
System.arraycopy(bytes, 0, msgidBytes, 0, Constants.COMMAND_LENGTH);
int msgid = NumberUtils.bytesToInt(msgidBytes);
if (msgid != 0) {
//通过工厂方法生成指定消息类型的指令对象
BaseCommand command = CommandFactory.createCommand(msgid);
byte[] cmdBodyBytes = new byte[length - Constants.COMMAND_LENGTH];
System.arraycopy(bytes, Constants.COMMAND_LENGTH, cmdBodyBytes, 0, length - Constants.COMMAND_LENGTH);
command.bodyFromBytes(cmdBodyBytes);
out.write(command);
return true;
}
}
return false;
}
示例7: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
public boolean doDecode(IoSession session, IoBuffer in,
ProtocolDecoderOutput out) throws Exception {
// log.debug("doDecode(...)...");
XMLLightweightParser parser = (XMLLightweightParser) session
.getAttribute(XmppIoHandler.XML_PARSER);
parser.read(in);
// 如果有消息
if (parser.areThereMsgs()) {
for (String stanza : parser.getMsgs()) {
out.write(stanza);
}
}
// 是否还有剩余
return !in.hasRemaining();
}
示例8: getDecoder
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
public ProtocolDecoder getDecoder(IoSession is) throws Exception {
return new CumulativeProtocolDecoder() {
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
if (in.remaining() > 0) {
byte[] buf = new byte[in.remaining()];
in.get(buf);
out.write(new String(buf, "US-ASCII"));
return true;
} else {
return false;
}
}
};
}
示例9: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
public void decode(IoSession ioSession, IoBuffer ioBuffer, ProtocolDecoderOutput out) throws Exception
{
byte[] message = new byte[ioBuffer.limit()];
ioBuffer.get(message);
UltravoxMessage ultravoxMessage = UltravoxMessageFactory.getMessage(message);
if(ultravoxMessage != null)
{
out.write(ultravoxMessage);
}
else
{
out.write(message);
}
}
示例10: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession is, IoBuffer ib, ProtocolDecoderOutput pdo) throws Exception {
synchronized (is) {
final MessageCodec stats = getSessionCodec(is);
// 消息
SessionMessage message = null;
// 消息不等于空,循环读取消息
do {
message = stats.readMessage(is, ib);
if (message != null) {
pdo.write(message);
}
} while (message != null);
// 调试输出
// System.out.println(ib);
return message != null;
}
}
示例11: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
RedisProtocolParser parser = (RedisProtocolParser) session.getAttribute(REDIS_PROTOCOL_PARSER);
// 将接收到的数据通过解析器解析为Redis数据包对象
parser.read(in.buf());
// 获取解析器解析出的数据包
RedisPacket[] redisPackets = parser.getPackets();
if (redisPackets != null) {
for (RedisPacket redisPacket : redisPackets) {
out.write(redisPacket);
}
}
// 以是否读取完数据为判断符
return !in.hasRemaining();
}
示例12: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
if (in.remaining() < 4) {
return false;
}
in.mark(); // mark 2 reset, reset call rollback to mark place
int dataLength = in.getInt(); // data length
if (dataLength < in.remaining()) {
return false;
}
if (dataLength > in.remaining()) {
in.reset();
}
byte[] datas = new byte[dataLength]; // data
in.get(datas, 0, dataLength);
Object obj = serializer.deserialize(datas, genericClass);
out.write(obj);
return true;
}
示例13: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
/**
* 解码并处理断包
*/
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer buffer, ProtocolDecoderOutput output)
throws Exception {
int nRemainning = buffer.remaining();
if (nRemainning < MessageCodec.HEAD_LENGTH) {// min length
return MessageDecoderResult.NEED_DATA;
} else {
buffer.mark();// 标记位置mark=pos
int nLen = buffer.getShort();// 包长(包括消息头)
buffer.reset();// 重置位置pos=mark
// 如果buffer中可读的长度小于包长说明断包返回 NEED_DATA
if (nRemainning < nLen) {
// buffer.reset();//重置位置pos=mark
return MessageDecoderResult.NEED_DATA;
}
// buffer.reset();//重置位置pos=mark
}
Object proObj = decodeBody(session, buffer);
output.write(proObj);// 解码后输出
return MessageDecoderResult.OK;
}
示例14: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
protected final boolean doDecode(IoSession session, IoBuffer buf, ProtocolDecoderOutput out) throws Exception {
/*byte cmd = buf.get();
byte error = buf.get();
byte b1 = buf.get();
byte b2 = buf.get();
short packetLength = (short) (b2 & 0xFF << 8 | b1 & 0xFF);
int length = buf.remaining();
if (packetLength >= length) {
byte[] in = new byte[packetLength + 4];
in[0] = cmd;
in[1] = error;
in[2] = b1;
in[3] = b2;
buf.get(in, 4, packetLength);
out.write(in);
return true;
}
return false;*/
int length = buf.remaining();
byte[] input = new byte[length];
buf.get(input, 0, length);
out.write(input);
return true;
}
示例15: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入方法依赖的package包/类
@Override
public boolean doDecode(IoSession session, IoBuffer in,
ProtocolDecoderOutput out) throws Exception {
log.debug("doDecode(...)...");
// Get the XML light parser from the IoSession
XMLLightweightParser parser = (XMLLightweightParser) session
.getAttribute("XML-PARSER");
// Parse as many stanzas as possible from the received data
parser.read(in);
if (parser.areThereMsgs()) {
for (String stanza : parser.getMsgs()) {
out.write(stanza);
}
}
return !in.hasRemaining();
}