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


Java IoBuffer类代码示例

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


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

示例1: decode

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的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 );
    }
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:29,代码来源:LdapProtocolDecoder.java

示例2: encodeDoubleCollection

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
@Override
public void encodeDoubleCollection ( final IoBuffer buffer, final byte fieldNumber, final Collection<Double> data ) throws Exception
{
    buffer.put ( fieldNumber );
    if ( data != null )
    {
        buffer.put ( TYPE_DOUBLE_LIST );
        buffer.putInt ( data.size () );
        for ( final Double entry : data )
        {
            buffer.putDouble ( entry );
        }
    }
    else
    {
        buffer.put ( TYPE_NULL );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:DefaultBinaryContext.java

示例3: decodePropertiesCollection

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
private <T extends Collection<Map<String, String>>> T decodePropertiesCollection ( final IoBuffer buffer, final CollectionAllocator<Map<String, String>, T> allactor ) throws Exception
{
    final byte type = checkType ( buffer, TYPE_PROPERTIES_LIST, true );

    if ( type == TYPE_NULL )
    {
        return null;
    }
    else
    {
        final int items = buffer.getInt ();
        final T result = allactor.allocate ( items );
        fillPropertiesCollection ( buffer, items, result );
        return result;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:DefaultBinaryContext.java

示例4: estimateSize

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
/**
 * Estimate the size of an Objecr in number of bytes
 * @param message The object to estimate
 * @return The estimated size of the object
 */
public int estimateSize(Object message) {
    if (message == null) {
        return 8;
    }

    int answer = 8 + estimateSize(message.getClass(), null);

    if (message instanceof IoBuffer) {
        answer += ((IoBuffer) message).remaining();
    } else if (message instanceof WriteRequest) {
        answer += estimateSize(((WriteRequest) message).getMessage());
    } else if (message instanceof CharSequence) {
        answer += ((CharSequence) message).length() << 1;
    } else if (message instanceof Iterable) {
        for (Object m : (Iterable<?>) message) {
            answer += estimateSize(m);
        }
    }

    return align(answer);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:DefaultIoEventSizeEstimator.java

示例5: decode

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:ModbusRtuDecoder.java

示例6: decode

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:IntegerDecodingState.java

示例7: messageReceived

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
@Override
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
    AbstractIoSession s = (AbstractIoSession) session;
    if (!(message instanceof IoBuffer)) {
        s.increaseReadMessages(System.currentTimeMillis());
    } else if (!((IoBuffer) message).hasRemaining()) {
        s.increaseReadMessages(System.currentTimeMillis());
    }

    try {
        session.getHandler().messageReceived(s, message);
    } finally {
        if (s.getConfig().isUseReadOperation()) {
            s.offerReadFuture(message);
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:18,代码来源:DefaultIoFilterChain.java

示例8: getSize

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
public long getSize ()
{
    long size = 0;
    for ( final Object data : this.queue )
    {
        if ( data instanceof IoBuffer )
        {
            size += ( (IoBuffer)data ).remaining ();
        }
        else
        {
            throw new IllegalArgumentException ( "Can only handle IoBuffers" );
        }
    }
    return size;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:SizeTest.java

示例9: handleResponse

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
/**
 * Handle a SOCKS4/SOCKS4a response from the proxy server. Test
 * the response buffer reply code and call {@link #setHandshakeComplete()}
 * if access is granted.
 * 
 * @param buf the buffer holding the server response data.
 * @throws exception if server response is malformed or if request is rejected
 * by the proxy server.
 */
protected void handleResponse(final IoBuffer buf) throws Exception {
    byte first = buf.get(0);

    if (first != 0) {
        throw new Exception("Socks response seems to be malformed");
    }

    byte status = buf.get(1);

    // Consumes all the response data from the buffer
    buf.position(buf.position() + SocksProxyConstants.SOCKS_4_RESPONSE_SIZE);

    if (status == SocksProxyConstants.V4_REPLY_REQUEST_GRANTED) {
        setHandshakeComplete();
    } else {
        throw new Exception("Proxy handshake failed - Code: 0x" + ByteUtilities.asHex(new byte[] { status }) + " ("
                + SocksProxyConstants.getReplyCodeAsString(status) + ")");
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:29,代码来源:Socks4LogicHandler.java

示例10: processBrowseAdded

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:ProtocolDecoderImpl.java

示例11: increaseWrittenMessages

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
/**
 * TODO Add method documentation
 */
public final void increaseWrittenMessages(WriteRequest request, long currentTime) {
    Object message = request.getMessage();
    if (message instanceof IoBuffer) {
        IoBuffer b = (IoBuffer) message;
        if (b.hasRemaining()) {
            return;
        }
    }

    writtenMessages++;
    lastWriteTime = currentTime;
    if (getService() instanceof AbstractIoService) {
        ((AbstractIoService) getService()).getStatistics().increaseWrittenMessages(currentTime);
    }

    decreaseScheduledWriteMessages();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:AbstractIoSession.java

示例12: decodeLongCollection

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
private <T extends Collection<Long>> T decodeLongCollection ( final IoBuffer buffer, final CollectionAllocator<Long, T> allactor ) throws Exception
{
    final byte type = checkType ( buffer, TYPE_LONG_LIST, true );

    if ( type == TYPE_NULL )
    {
        return null;
    }
    else
    {
        final int items = buffer.getInt ();
        final T result = allactor.allocate ( items );
        fillLongCollection ( buffer, items, result );
        return result;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:DefaultBinaryContext.java

示例13: handleDT

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
/**
 * Handle data transmission
 * 
 * @param nextFilter
 * @param session
 * @param writeRequest
 */
private void handleDT ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest )
{
    final DataTPDU userData = (DataTPDU)writeRequest.getMessage ();
    final IoBuffer data = IoBuffer.allocate ( userData.getData ().remaining () + 3 );

    data.put ( (byte)0x02 ); // header length
    data.put ( (byte) ( COMMAND_DATA << 4 ) );

    final byte seq = (byte)0x80; // bit 8 to 1 (last packet)... bit 7..1 to zero (packet #0)

    data.put ( seq );

    data.put ( userData.getData () );

    data.flip ();

    nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
        @Override
        public Object getMessage ()
        {
            return data;
        }
    } );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:32,代码来源:COTPFilter.java

示例14: get

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
/**
 * @inheritDoc
 */
public void get(IoBuffer bb) {
    while (bb.hasRemaining()) {
        int remainingBefore = bb.remaining();
        prepareForAccess(remainingBefore);
        componentCursor.get(bb);
        int remainingAfter = bb.remaining();
        // Advance index by actual amount got.
        int chunkSize = remainingBefore - remainingAfter;
        index += chunkSize;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:CompositeByteArray.java

示例15: encodeMessage

import org.apache.mina.core.buffer.IoBuffer; //导入依赖的package包/类
@Override
public IoBuffer encodeMessage ( final BinaryContext context, final Object objectMessage ) throws Exception
{
    final IoBuffer data = IoBuffer.allocate ( 5 );
    data.putInt ( MESSAGE_CODE );
    data.put ( (byte)0 ); // number of fields 

    data.flip ();
    return data;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:11,代码来源:StartBrowse.java


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