Java Code Examples for org.apache.mina.core.buffer.IoBuffer#buf()

The following examples show how to use org.apache.mina.core.buffer.IoBuffer#buf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapProtocolDecoder.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws Exception
{
    @SuppressWarnings("unchecked")
    LdapMessageContainer<AbstractMessage> messageContainer =
        ( LdapMessageContainer<AbstractMessage> )
        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 );
    }
}
 
Example 2
Source File: IOUtils.java    From red5-io with Apache License 2.0 5 votes vote down vote up
/**
 * String representation of byte buffer
 * 
 * @param buf Byte buffer
 * @return String representation
 */
public final static String toString(IoBuffer buf) {
    int pos = buf.position();
    int limit = buf.limit();
    final java.nio.ByteBuffer strBuf = buf.buf();
    final String string = CHARSET.decode(strBuf).toString();
    buf.position(pos);
    buf.limit(limit);
    return string;
}
 
Example 3
Source File: TftpProtocolCodecFactory.java    From tftp4j with Apache License 2.0 4 votes vote down vote up
@Override
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    TftpPacket packet = super.decode(session.getRemoteAddress(), in.buf());
    out.write(packet);
}