org.apache.mina.common.ByteBuffer.flip()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中org.apache.mina.common.ByteBuffer.flip()方法的一些代码示例,展示了ByteBuffer.flip()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.flip()方法的具体详情如下:
包路径:org.apache.mina.common.ByteBuffer
类名称:ByteBuffer
方法名:flip

ByteBuffer.flip介绍

暂无

代码示例

代码示例来源:origin: org.apache.directory.mina/mina-core

public ByteBuffer flip()
{
  buf.flip();
  return this;
}

代码示例来源:origin: org.apache.mina/mina-filter-ssl

/**
 * Creates a new Mina byte buffer that is a deep copy of the remaining bytes
 * in the given buffer (between index buf.position() and buf.limit())
 *
 * @param src the buffer to copy
 * @return the new buffer, ready to read from
 */
public static org.apache.mina.common.ByteBuffer copy(java.nio.ByteBuffer src) {
  org.apache.mina.common.ByteBuffer copy = org.apache.mina.common.ByteBuffer
      .allocate(src.remaining());
  copy.put(src);
  copy.flip();
  return copy;
}

代码示例来源:origin: alibaba/tair-java-client

public void encode(IoSession session, Object message,
    ProtocolEncoderOutput out) throws Exception {
  if(!(message instanceof byte[])){
    throw new Exception("must send byte[]");
  }
  byte[] payload=(byte[]) message;
  ByteBuffer buf = ByteBuffer.allocate(payload.length, false);
  buf.put(payload);
  buf.flip();
  out.write(buf);
  if (isDebugEnabled)
    LOGGER.debug(TairUtil.toHex(payload));
}

代码示例来源:origin: org.apache.directory.mina/mina-core

public void write( ByteBuffer src )
{
  synchronized( mutex )
  {
    if( closed )
    {
      return;
    }
    if( buf.hasRemaining() )
    {
      this.buf.compact();
      this.buf.put( src );
      this.buf.flip();
    }
    else
    {
      this.buf.clear();
      this.buf.put( src );
      this.buf.flip();
      mutex.notifyAll();
    }
  }
}

代码示例来源:origin: org.apache.directory.mina/mina-core

public void write( int b ) throws IOException
  {
    ByteBuffer buf = ByteBuffer.allocate( 1 );
    buf.put( ( byte ) b );
    buf.flip();
    write( buf );
  }
}

代码示例来源:origin: org.apache.directory.mina/mina-core

public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws Exception
  {
    if( !( message instanceof Serializable ) )
    {
      throw new NotSerializableException();
    }

    ByteBuffer buf = ByteBuffer.allocate( 64 );
    buf.setAutoExpand( true );
    buf.putObject( message );
    
    int objectSize = buf.position() - 4;
    if( objectSize > maxObjectSize )
    {
      buf.release();
      throw new IllegalArgumentException( "The encoded object is too big: " + objectSize + " (> " + maxObjectSize + ')' );
    }
    
    buf.flip();
    out.write( buf );
  }
}

代码示例来源:origin: org.reddwarfserver.client/sgs-client

/**
   * Prepends the length of the given byte array as a 2-byte {@code short}
   * in network byte-order, and passes the result to the {@linkplain
   * FilterListener#sendUnfiltered sendUnfiltered} method of the
   * given {@code listener}.
   *
   * @param listener the {@code FilterListener} on which to send the data
   * @param message the data to filter and forward to the listener
   */
  void filterSend(FilterListener listener, byte[] message) {
    ByteBuffer buffer = ByteBuffer.allocate(message.length + 2, false);
    buffer.putShort((short) message.length);
    buffer.put(message);
    buffer.flip();
    // Don't worry about the listener throwing an exception, since
    // this method has no other side effects.
    listener.sendUnfiltered(buffer);
  }
}

代码示例来源:origin: org.apache.directory.mina/mina-core

public void encode( IoSession session, Object message,
          ProtocolEncoderOutput out )
    throws Exception
{
  CharsetEncoder encoder = ( CharsetEncoder ) session.getAttribute( ENCODER );
  if( encoder == null )
  {
    encoder = charset.newEncoder();
    session.setAttribute( ENCODER, encoder );
  }
  
  String value = message.toString();
  ByteBuffer buf = ByteBuffer.allocate( value.length() ).setAutoExpand( true );
  buf.putString( value, encoder );
  if( buf.position() > maxLineLength )
  {
    throw new IllegalArgumentException( "Line length: " + buf.position() );
  }
  buf.putString( delimiter.getValue(), encoder );
  buf.flip();
  out.write( buf );
}

代码示例来源:origin: org.reddwarfserver.client/sgs-client

/**
 * Processes network data of arbitrary length and dispatches zero or
 * more complete messages to the given {@code listener}.  If a partial
 * message remains, it is buffered until more data is received.
 *
 * @param listener the {@code FilterListener} to receive complete messages
 * @param buf the data to filter and optionally deliver to the
 *        {@code FilterListener}
 */
void filterReceive(FilterListener listener, ByteBuffer buf) {
  logger.log(Level.FINEST,
    "processing {0,number,#} bytes",
    buf.remaining());
  // Append the new data to the buffer
  msgBuf.expand(buf.remaining());
  msgBuf.put(buf);
  msgBuf.flip();
  processReceiveBuffer(listener);
}

代码示例来源:origin: org.apache.directory.mina/mina-core

private void readSession( DatagramSessionImpl session )
{
  ByteBuffer readBuf = ByteBuffer.allocate( session.getReadBufferSize() );
  try
  {
    int readBytes = session.getChannel().read( readBuf.buf() );
    if( readBytes > 0 )
    {
      readBuf.flip();
      ByteBuffer newBuf = ByteBuffer.allocate( readBuf.limit() );
      newBuf.put( readBuf );
      newBuf.flip();
      session.increaseReadBytes( readBytes );
      ( ( DatagramFilterChain ) session.getFilterChain() ).messageReceived( session, newBuf );
    }
  }
  catch( IOException e )
  {
    ( ( DatagramFilterChain ) session.getFilterChain() ).exceptionCaught( session, e );
  }
  finally
  {
    readBuf.release();
  }
}

代码示例来源:origin: org.apache.directory.mina/mina-core

private void readSession( DatagramSessionImpl session )
{
  ByteBuffer readBuf = ByteBuffer.allocate( session.getReadBufferSize() );
  try
  {
    SocketAddress remoteAddress = session.getChannel().receive(
        readBuf.buf() );
    if( remoteAddress != null )
    {
      readBuf.flip();
      session.setRemoteAddress( remoteAddress );
      ByteBuffer newBuf = ByteBuffer.allocate( readBuf.limit() );
      newBuf.put( readBuf );
      newBuf.flip();
      session.increaseReadBytes( newBuf.remaining() );
      ( ( DatagramFilterChain ) session.getFilterChain() ).messageReceived( session, newBuf );
    }
  }
  catch( IOException e )
  {
    ( ( DatagramFilterChain ) session.getFilterChain() ).exceptionCaught( session, e );
  }
  finally
  {
    readBuf.release();
  }
}

代码示例来源:origin: org.apache.directory.mina/mina-core

buf.flip();

代码示例来源:origin: org.apache.directory.mina/mina-core

newBuf.flip();
bufferQueue.push(newBuf);

代码示例来源:origin: org.apache.directory.mina/mina-core

buf.flip();

代码示例来源:origin: org.apache.directory.server/mitosis

public final void encode( IoSession session, Object in, ProtocolEncoderOutput out ) throws Exception
{
  BaseMessage m = ( BaseMessage ) in;
  ByteBuffer buf = ByteBuffer.allocate( 16 );
  buf.setAutoExpand( true );
  buf.put( ( byte ) m.getType() );
  buf.putInt( m.getSequence() );
  buf.putInt( 0 ); // placeholder for body length field
  final int bodyStartPos = buf.position();
  encodeBody( m, buf );
  final int bodyEndPos = buf.position();
  final int bodyLength = bodyEndPos - bodyStartPos;
  // fill bodyLength
  buf.position( bodyStartPos - 4 );
  buf.putInt( bodyLength );
  buf.position( bodyEndPos );
  buf.flip();
  out.write( buf );
}

代码示例来源:origin: org.apache.directory.mina/mina-core

tmp.flip();
delimBuf = tmp;
    buf.flip();
    out.write( buf.getString( decoder ) );
    buf.clear();

代码示例来源:origin: org.apache.directory.mina/mina-core

ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
wb.put( rb );
wb.flip();
rb.reset();
messageCopy = wb;

代码示例来源:origin: org.apache.directory.mina/mina-core

buf.flip();
out.write( buf.getString( decoder ) );
buf.clear();

相关文章