private ByteBuffer encodeAndAllocateBuffer ( String key ) { if ( key == null ) { return ByteBuffer . wrap ( EMPTY ) ; } CharsetEncoder encoder = CharsetUtil . encoder ( charset ) ; ByteBuffer buffer = ByteBuffer . allocate ( ( int ) ( encoder . maxBytesPerChar ( ) * key . length ( ) ) ) ; ByteBuf byteBuf = Unpooled . wrappedBuffer ( buffer ) ; byteBuf . clear ( ) ; encode ( key , byteBuf ) ; buffer . limit ( byteBuf . writerIndex ( ) ) ; return buffer ; }
Compatibility implementation .