當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。