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

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

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

ByteBuffer.remaining介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-dubbo

frame = buffer;
} else {
  int size = buffer.readableBytes() + in.remaining();
  frame = ChannelBuffers.dynamicBuffer(size > bufferSize ? size : bufferSize);
  frame.writeBytes(buffer, buffer.readableBytes());

代码示例来源:origin: apache/incubator-dubbo

frame = buffer;
} else {
  int size = buffer.readableBytes() + in.remaining();
  frame = ChannelBuffers.dynamicBuffer(size > bufferSize ? size : bufferSize);
  frame.writeBytes(buffer, buffer.readableBytes());

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

public int remaining()
{
  return buf.remaining();
}

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

public int available()
{
  return ByteBuffer.this.remaining();
}

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

/**
 * @see java.nio.Buffer#hasRemaining()
 */
public boolean hasRemaining()
{
  return remaining() > 0;
}

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

public int available()
{
  if( released )
  {
    return 0;
  }
  else
  {
    synchronized( mutex )
    {
      return buf.remaining();
    }
  }
}

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

public long skip( long n )
  {
    int bytes;
    if( n > Integer.MAX_VALUE )
    {
      bytes = ByteBuffer.this.remaining();
    }
    else
    {
      bytes = Math.min( ByteBuffer.this.remaining(), (int)n );
    }
    ByteBuffer.this.skip( bytes );
    return bytes;
  }
};

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

public void messageReceived( NextFilter nextFilter, IoSession session, Object message ) throws Exception
  {
    if( message instanceof ByteBuffer )
    {
      add( session, ( (ByteBuffer)message ).remaining() );
    }
    nextFilter.messageReceived( session, message );
  }
}

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

public int read( byte[] b, int off, int len )
{
  int remaining = ByteBuffer.this.remaining();
  if( remaining > 0 )
  {
    int readBytes = Math.min( remaining, len );
    ByteBuffer.this.get( b, off, readBytes );
    return readBytes;
  }
  else
  {
    return -1;
  }
}

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

public int read( byte[] b, int off, int len ) throws IOException
{
  synchronized( mutex )
  {
    if( !waitForData() )
    {
      return -1;
    }
    int readBytes;
    if( len > buf.remaining() )
    {
      readBytes = buf.remaining();
    }
    else
    {
      readBytes = len;
    }
    buf.get( b, off, readBytes );
    return readBytes;
  }
}

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

public int compareTo( Object o )
{
  ByteBuffer that = (ByteBuffer)o;
  int n = this.position() + Math.min( this.remaining(), that.remaining() );
  for( int i = this.position(), j = that.position(); i < n; i ++, j ++ )
  {
    byte v1 = this.get( i );
    byte v2 = that.get( j );
    if( v1 == v2 )
    {
      continue;
    }
    if( v1 < v2 )
    {
      return -1;
    }
    return +1;
  }
  return this.remaining() - that.remaining();
}

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

/**
 * Dispatches a complete message to this connection's
 * {@code ConnectionListener}.
 * 
 * @param buf a {@code MINA ByteBuffer} containing the message to dispatch
 */
public void filteredMessageReceived(ByteBuffer buf) {
  byte[] message = new byte[buf.remaining()];
  buf.get(message);
  listener.bytesReceived(this, message);
}

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

/**
 * Clears this buffer and fills its content with <tt>value</tt>.
 * The position is set to zero, the limit is set to the capacity,
 * and the mark is discarded.
 */
public ByteBuffer sweep( byte value )
{
  clear();
  return fillAndReset( value, remaining() );
}

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

/**
 * Clears this buffer and fills its content with <tt>NUL</tt>.
 * The position is set to zero, the limit is set to the capacity,
 * and the mark is discarded.
 */
public ByteBuffer sweep()
{
  clear();
  return fillAndReset( remaining() );
}

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

public static String getHexdump( ByteBuffer in )
  int size = in.remaining();
  StringBuffer out = new StringBuffer( ( in.remaining() * 3 ) - 1 );

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

protected BaseMessage decodeBody( Registries registries, int sequence, int bodyLength, ByteBuffer in ) throws Exception
{
  byte[] src = new byte[in.remaining()];
  in.get( src );
  return new LogEntryMessage( sequence, operationCodec.decode( registries, src ) );
}

代码示例来源: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

public boolean equals( Object o )
{
  if( !( o instanceof ByteBuffer ) )
  {
    return false;
  }
  ByteBuffer that = (ByteBuffer)o;
  if( this.remaining() != that.remaining() )
  {
    return false;
  }
  int p = this.position();
  for( int i = this.limit() - 1, j = that.limit() - 1; i >= p; i --, j -- )
  {
    byte v1 = this.get( i );
    byte v2 = that.get( j );
    if( v1 != v2 )
    {
      return false;
    }
  }
  return true;
}

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

private void storeRemainingInSession(ByteBuffer buf, IoSession session)
  {
    ByteBuffer remainingBuf = ByteBuffer.allocate( buf.remaining() );
    remainingBuf.setAutoExpand( true );
    remainingBuf.put( buf );
    session.setAttribute( BUFFER, remainingBuf );
  }    
}

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

public void messageReceived( IoSession session, Object message )
{
  VmPipeSessionImpl s = ( VmPipeSessionImpl ) session;
  synchronized( s.lock )
  {
    if( !s.getTrafficMask().isReadable() )
    {
      synchronized( s.pendingDataQueue )
      {
        s.pendingDataQueue.push( message );
      }
    }
    else
    {
      int byteCount = 1;
      if( message instanceof ByteBuffer )
      {
        byteCount = ( ( ByteBuffer ) message ).remaining();
      }
      
      s.increaseReadBytes( byteCount );
      
      super.messageReceived( s, message );
    }
  }
}

相关文章