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