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


Java IoBuffer.hasRemaining方法代码示例

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


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

示例1: doFilterWrite

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
protected Object doFilterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
        throws IOException {
    if (!compressOutbound) {
        return null;
    }

    if (session.containsAttribute(DISABLE_COMPRESSION_ONCE)) {
        // Remove the marker attribute because it is temporary.
        session.removeAttribute(DISABLE_COMPRESSION_ONCE);
        return null;
    }

    Zlib deflater = (Zlib) session.getAttribute(DEFLATER);
    if (deflater == null) {
        throw new IllegalStateException();
    }

    IoBuffer inBuffer = (IoBuffer) writeRequest.getMessage();
    if (!inBuffer.hasRemaining()) {
        // Ignore empty buffers
        return null;
    } else {
        return deflater.deflate(inBuffer);
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:CompressionFilter.java

示例2: 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

示例3: decreaseScheduledBytesAndMessages

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * TODO Add method documentation
 */
public final void decreaseScheduledBytesAndMessages(WriteRequest request) {
    Object message = request.getMessage();
    if (message instanceof IoBuffer) {
        IoBuffer b = (IoBuffer) message;
        if (b.hasRemaining()) {
            increaseScheduledWriteBytes(-((IoBuffer) message).remaining());
        } else {
            decreaseScheduledWriteMessages();
        }
    } else {
        decreaseScheduledWriteMessages();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:AbstractIoSession.java

示例4: decodeResponseConfiguration

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void decodeResponseConfiguration ( final IoBuffer data, final ProtocolDecoderOutput output, final int sequence )
{
    final byte nin = data.get ();
    final byte nout = data.get ();

    @SuppressWarnings ( "unchecked" )
    final Map<Integer, Object> parameters[] = new Map[nin + nout];

    while ( data.hasRemaining () )
    {
        final byte type = data.get ();
        final byte signalNumber = data.get ();
        final byte len = data.get ();

        final byte[] dataBuffer = new byte[len];
        data.get ( dataBuffer );

        if ( parameters[signalNumber] == null )
        {
            parameters[signalNumber] = new HashMap<Integer, Object> ();
        }
        parameters[signalNumber].put ( (int)type, convertData ( type, dataBuffer ) );
    }

    final ConfigurationMessage msg = new ConfigurationMessage ( sequence, CommandCode.RESPOND_CONFIGURATION, parameters );
    output.write ( msg );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:28,代码来源:ArduinoCodec.java

示例5: messageReceived

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * Receives data from the remote host, passes to the handler if a handshake is in progress, 
 * otherwise passes on transparently.
 * 
 * @param nextFilter the next filter in filter chain
 * @param session the session object
 * @param message the object holding the received data
 */
@Override
public void messageReceived(final NextFilter nextFilter, final IoSession session, final Object message)
        throws ProxyAuthException {
    ProxyLogicHandler handler = getProxyHandler(session);

    synchronized (handler) {
        IoBuffer buf = (IoBuffer) message;

        if (handler.isHandshakeComplete()) {
            // Handshake done - pass data on as-is
            nextFilter.messageReceived(session, buf);

        } else {
            LOGGER.debug(" Data Read: {} ({})", handler, buf);

            // Keep sending handshake data to the handler until we run out
            // of data or the handshake is finished
            while (buf.hasRemaining() && !handler.isHandshakeComplete()) {
                LOGGER.debug(" Pre-handshake - passing to handler");

                int pos = buf.position();
                handler.messageReceived(nextFilter, buf);

                // Data not consumed or session closing
                if (buf.position() == pos || session.isClosing()) {
                    return;
                }
            }

            // Pass on any remaining data to the next filter
            if (buf.hasRemaining()) {
                LOGGER.debug(" Passing remaining data to next filter");

                nextFilter.messageReceived(session, buf);
            }
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:47,代码来源:ProxyFilter.java

示例6: 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

示例7: put

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

示例8: handleAppDataRead

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void handleAppDataRead(NextFilter nextFilter, SslHandler handler) {
    // forward read app data
    IoBuffer readBuffer = handler.fetchAppBuffer();

    if (readBuffer.hasRemaining()) {
        handler.scheduleMessageReceived(nextFilter, readBuffer);
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:9,代码来源:SslFilter.java

示例9: decode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    if (in.hasRemaining()) {
        return finishDecode(in.get(), out);
    }

    return this;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:SingleByteDecodingState.java

示例10: decode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    boolean found = false;
    boolean finished = false;
    while (in.hasRemaining()) {
        byte b = in.get();
        if (!hasCR) {
            if (b == CR) {
                hasCR = true;
            } else {
                if (b == LF) {
                    found = true;
                } else {
                    in.position(in.position() - 1);
                    found = false;
                }
                finished = true;
                break;
            }
        } else {
            if (b == LF) {
                found = true;
                finished = true;
                break;
            }

            throw new ProtocolDecoderException("Expected LF after CR but was: " + (b & 0xff));
        }
    }

    if (finished) {
        hasCR = false;
        return finishDecode(found, out);
    }

    return this;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:40,代码来源:CrLfDecodingState.java

示例11: write

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
public void write(Object encodedMessage) {
    if (encodedMessage instanceof IoBuffer) {
        IoBuffer buf = (IoBuffer) encodedMessage;
        if (buf.hasRemaining()) {
            messageQueue.offer(buf);
        } else {
            throw new IllegalArgumentException("buf is empty. Forgot to call flip()?");
        }
    } else {
        messageQueue.offer(encodedMessage);
        buffersOnly = false;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:14,代码来源:AbstractProtocolEncoderOutput.java

示例12: writeBuffer

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private int writeBuffer(S session, WriteRequest req, boolean hasFragmentation, int maxLength, long currentTime)
        throws Exception {
    IoBuffer buf = (IoBuffer) req.getMessage();
    int localWrittenBytes = 0;

    if (buf.hasRemaining()) {
        int length;

        if (hasFragmentation) {
            length = Math.min(buf.remaining(), maxLength);
        } else {
            length = buf.remaining();
        }

        try {
            localWrittenBytes = write(session, buf, length);
        } catch (IOException ioe) {
            // We have had an issue while trying to send data to the 
            // peer : let's close the session.
            session.close(true);
        }

    }

    session.increaseWrittenBytes(localWrittenBytes, currentTime);

    if (!buf.hasRemaining() || (!hasFragmentation && (localWrittenBytes != 0))) {
        // Buffer has been sent, clear the current request.
        int pos = buf.position();
        buf.reset();

        fireMessageSent(session, req);

        // And set it back to its position
        buf.position(pos);
    }

    return localWrittenBytes;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:40,代码来源:AbstractPollingIoProcessor.java

示例13: messageReceived

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void messageReceived ( final NextFilter nextFilter, final IoSession session, final Object message ) throws Exception
{
    if ( ! ( message instanceof IoBuffer ) )
    {
        nextFilter.messageReceived ( session, message );
        return;
    }

    final IoBuffer in = (IoBuffer)message;
    final IoBuffer sessionBuffer = getSessionBuffer ( session );

    // first add to the session buffer (may be optimized later)
    sessionBuffer.position ( sessionBuffer.limit () );
    sessionBuffer.put ( in );
    sessionBuffer.flip ();

    while ( sessionBuffer.remaining () >= 4 )
    {
        final int len = sessionBuffer.getUnsignedShort ( 2 );
        if ( sessionBuffer.remaining () < len )
        {
            logger.debug ( "Next packet requires {} bytes", new Object[] { len } );
            // not enough data for body
            return;
        }

        // convert
        final IoBuffer data = IoBuffer.allocate ( len - 4 );
        sessionBuffer.get (); // version
        sessionBuffer.get (); // reserved
        sessionBuffer.getUnsignedShort (); // length

        sessionBuffer.get ( data.array () );

        nextFilter.messageReceived ( session, data );

        logger.debug ( "{} bytes left in session buffer", sessionBuffer.remaining () );
    }

    if ( sessionBuffer.hasRemaining () )
    {
        sessionBuffer.compact ();
    }
    else
    {
        sessionBuffer.clear ().flip ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:50,代码来源:TPKTFilter.java

示例14: messageReceived

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws SSLException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("{}: Message received : {}", getSessionInfo(session), message);
    }

    SslHandler handler = getSslSessionHandler(session);

    synchronized (handler) {
        if (!isSslStarted(session) && handler.isInboundDone()) {
            // The SSL session must be established first before we
            // can push data to the application. Store the incoming
            // data into a queue for a later processing
            handler.scheduleMessageReceived(nextFilter, message);
        } else {
            IoBuffer buf = (IoBuffer) message;

            try {
                // forward read encrypted data to SSL handler
                handler.messageReceived(nextFilter, buf.buf());

                // Handle data to be forwarded to application or written to net
                handleSslData(nextFilter, handler);

                if (handler.isInboundDone()) {
                    if (handler.isOutboundDone()) {
                        handler.destroy();
                    } else {
                        initiateClosure(nextFilter, session);
                    }

                    if (buf.hasRemaining()) {
                        // Forward the data received after closure.
                        handler.scheduleMessageReceived(nextFilter, buf);
                    }
                }
            } catch (SSLException ssle) {
                if (!handler.isHandshakeComplete()) {
                    SSLException newSsle = new SSLHandshakeException("SSL handshake failed.");
                    newSsle.initCause(ssle);
                    ssle = newSsle;
                }

                throw ssle;
            }
        }
    }

    handler.flushScheduledEvents();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:51,代码来源:SslFilter.java

示例15: messageReceived

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * Process the incoming message, calling the session decoder. As the incoming
 * buffer might contains more than one messages, we have to loop until the decoder
 * throws an exception.
 * 
 *  while ( buffer not empty )
 *    try
 *      decode ( buffer )
 *    catch
 *      break;
 * 
 */
@Override
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
    LOGGER.debug("Processing a MESSAGE_RECEIVED for session {}", session.getId());

    if (!(message instanceof IoBuffer)) {
        nextFilter.messageReceived(session, message);
        return;
    }

    IoBuffer in = (IoBuffer) message;
    ProtocolDecoder decoder = factory.getDecoder(session);
    ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter);

    // Loop until we don't have anymore byte in the buffer,
    // or until the decoder throws an unrecoverable exception or
    // can't decoder a message, because there are not enough
    // data in the buffer
    while (in.hasRemaining()) {
        int oldPos = in.position();

        try {
            synchronized (decoderOut) {
                // Call the decoder with the read bytes
                decoder.decode(session, in, decoderOut);
            }

            // Finish decoding if no exception was thrown.
            decoderOut.flush(nextFilter, session);
        } catch (Throwable t) {
            ProtocolDecoderException pde;
            if (t instanceof ProtocolDecoderException) {
                pde = (ProtocolDecoderException) t;
            } else {
                pde = new ProtocolDecoderException(t);
            }

            if (pde.getHexdump() == null) {
                // Generate a message hex dump
                int curPos = in.position();
                in.position(oldPos);
                pde.setHexdump(in.getHexDump());
                in.position(curPos);
            }

            // Fire the exceptionCaught event.
            decoderOut.flush(nextFilter, session);
            nextFilter.exceptionCaught(session, pde);

            // Retry only if the type of the caught exception is
            // recoverable and the buffer position has changed.
            // We check buffer position additionally to prevent an
            // infinite loop.
            if (!(t instanceof RecoverableProtocolDecoderException) || (in.position() == oldPos)) {
                break;
            }
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:71,代码来源:ProtocolCodecFilter.java


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