本文整理汇总了Java中org.apache.mina.filter.codec.ProtocolDecoderOutput类的典型用法代码示例。如果您正苦于以下问题:Java ProtocolDecoderOutput类的具体用法?Java ProtocolDecoderOutput怎么用?Java ProtocolDecoderOutput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtocolDecoderOutput类属于org.apache.mina.filter.codec包,在下文中一共展示了ProtocolDecoderOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
public MessageDecoderResult decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out)
throws ProtocolCodecException {
int messageCount = 0;
while (parseMessage(in, out)) {
messageCount++;
}
if (messageCount > 0) {
// Mina will compact the buffer because we can't detect a header
if (in.remaining() < HEADER_PATTERN.length) {
position = 0;
}
return MessageDecoderResult.OK;
} else {
// Mina will compact the buffer
position -= in.position();
return MessageDecoderResult.NEED_DATA;
}
}
示例2: doDecode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
final Pack pack = getPack(session);
if (!pack.headDone) {
if (in.remaining() < 8) {
return false;
} else {
int code = in.getInt();
int len = in.getInt();
pack.setHead(code, len);
}
}
int requires = pack.requires();
int remains = in.remaining();
int cpyLen = Math.min(requires, remains);
pack.readBytes(in, cpyLen);
requires = pack.requires();
if (requires == 0) {
out.write(pack.toMsg());
pack.reset();
return true;
}
return false;
}
示例3: 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 );
}
}
示例4: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
@Override
public synchronized void decode ( final IoSession session, final IoBuffer in, final ProtocolDecoderOutput out ) throws Exception
{
IoBuffer currentFrame = (IoBuffer)session.getAttribute ( SESSION_KEY_CURRENT_FRAME );
if ( currentFrame == null )
{
currentFrame = IoBuffer.allocate ( Constants.MAX_PDU_SIZE + Constants.RTU_HEADER_SIZE );
session.setAttribute ( SESSION_KEY_CURRENT_FRAME, currentFrame );
}
logger.trace ( "decode () current frame = {} data = {}", currentFrame.toString (), currentFrame.getHexDump () );
logger.trace ( "decode () new frame = {} data = {}", in.toString (), in.getHexDump () );
final int expectedSize = currentFrame.position () + in.remaining ();
if ( expectedSize > MAX_SIZE + 1 )
{
throw new ModbusProtocolError ( String.format ( "received size (%s) exceeds max size (%s)", expectedSize, MAX_SIZE ) );
}
currentFrame.put ( in );
tick ( session, out );
}
示例5: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
@Override
public void decode ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput output ) throws Exception
{
final short magic = data.getShort ();
final byte version = data.get ();
final int sequence = data.getInt ();
final byte commandCode = data.get ();
if ( magic != 1202 )
{
throw new ProtocolCodecException ( String.format ( "Magic code should be 1202 but is %s", magic ) );
}
if ( version != 1 )
{
throw new ProtocolCodecException ( String.format ( "Version should be %s but is %s", 1, version ) );
}
decodeMessage ( sequence, commandCode, data, output );
}
示例6: wrapTimeout
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
private void wrapTimeout ( final IoSession session, final ProtocolDecoderOutput out )
{
try
{
timeout ( session, out );
}
catch ( final Throwable e )
{
try
{
session.getHandler ().exceptionCaught ( session, e );
}
catch ( final Throwable ee )
{
logger.warn ( "Exception was thrown during handling Exception", ee );
}
}
}
示例7: check
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
public synchronized void check ()
{
if ( this.disposed )
{
return;
}
if ( this.lastData == null )
{
return;
}
if ( System.currentTimeMillis () - this.lastData > this.timeout )
{
final ProtocolDecoderOutput out = this.out;
TimedEndDecoder.this.clear ( this.session );
this.decoder.wrapTimeout ( this.session, out );
}
}
示例8: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
while (in.hasRemaining()) {
switch (counter) {
case 0:
firstByte = in.getUnsigned();
break;
case 1:
secondByte = in.getUnsigned();
break;
case 2:
thirdByte = in.getUnsigned();
break;
case 3:
counter = 0;
return finishDecode((firstByte << 24) | (secondByte << 16) | (thirdByte << 8) | in.getUnsigned(), out);
default:
throw new InternalError();
}
counter++;
}
return this;
}
示例9: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
int beginPos = in.position();
int limit = in.limit();
for (int i = beginPos; i < limit; i++) {
byte b = in.get(i);
if (!canSkip(b)) {
in.position(i);
int answer = this.skippedBytes;
this.skippedBytes = 0;
return finishDecode(answer);
}
skippedBytes++;
}
in.position(limit);
return this;
}
示例10: decode
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
while (in.hasRemaining()) {
switch (counter) {
case 0:
highByte = in.getUnsigned();
break;
case 1:
counter = 0;
return finishDecode((short) ((highByte << 8) | in.getUnsigned()), out);
default:
throw new InternalError();
}
counter++;
}
return this;
}
示例11: processWriteCommand
import org.apache.mina.filter.codec.ProtocolDecoderOutput; //导入依赖的package包/类
private boolean processWriteCommand ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
final int registerNumber = data.getUnsignedShort ();
final int operationId = data.getInt ();
final Variant value = decodeVariant ( session, data );
out.write ( new WriteCommand ( registerNumber, value, operationId ) );
return true;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}