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

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

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

ByteBuffer.position介绍

暂无

代码示例

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

public ByteBuffer position( int newPosition )
{
  buf.position( newPosition );
  return this;
}

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

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

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

/**
 * Forwards the position of this buffer as the specified <code>size</code>
 * bytes.
 */
public ByteBuffer skip( int size )
{
  autoExpand( size );
  return position( position() + size );
}

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

/**
 * @see java.nio.Buffer#remaining()
 */
public int remaining()
{
  return limit() - position();
}

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

/**
 * Changes the capacity and limit of this buffer so this buffer get
 * the specified <tt>expectedRemaining</tt> room from the current position.
 * This method works even if you didn't set <tt>autoExpand</tt> to
 * <tt>true</tt>.
 */
public ByteBuffer expand( int expectedRemaining )
{
  return expand( position(), expectedRemaining );
}

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

/**
 * Fills this buffer with the specified value.
 * This method does not change buffer position.
 */
public ByteBuffer fillAndReset( byte value, int size )
{
  autoExpand( size );
  int pos = position();
  try
  {
    fill( value, size );
  }
  finally
  {
    position( pos );
  }
  return this;
}

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

/**
 * Fills this buffer with <code>NUL (0x00)</code>.
 * This method does not change buffer position.
 */
public ByteBuffer fillAndReset( int size )
{
  autoExpand( size );
  int pos = position();
  try
  {
    fill( size );
  }
  finally
  {
    position( pos );
  }
  return this;
}

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

public int hashCode()
{
  int h = 1;
  int p = position();
  for( int i = limit() - 1; i >= p; i -- )
  {
    h = 31 * h + get( i );
  }
  return h;
}

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

/**
 * Writes the specified Java object to the buffer.
 */
public ByteBuffer putObject( Object o )
{
  int oldPos = position();
  skip( 4 ); // Make a room for the length field.
  try
  {
    ObjectOutputStream out = new ObjectOutputStream( asOutputStream() )
    {
      protected void writeClassDescriptor( ObjectStreamClass desc ) throws IOException
      {
        writeUTF( desc.getName() );
      }
    };
    out.writeObject( o );
    out.flush();
  }
  catch( IOException e )
  {
    throw new BufferDataException( e );
  }
  // Fill the length field
  int newPos = position();
  position( oldPos );
  putInt( newPos - oldPos - 4 );
  position( newPos );
  return this;
}

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

public String toString()
{
  StringBuffer buf = new StringBuffer();
  if( isDirect() )
  {
    buf.append( "DirectBuffer" );
  }
  else
  {
    buf.append( "HeapBuffer" );
  }
  buf.append( "[pos=" );
  buf.append( position() );
  buf.append( " lim=" );
  buf.append( limit() );
  buf.append( " cap=" );
  buf.append( capacity() );
  buf.append( ": " );
  buf.append( getHexDump() );
  buf.append( ']' );
  return buf.toString();
}

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

int mark = in.position();
in.position( mark );

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

dataLength = getUnsigned( position() );
  break;
case 2:
  dataLength = getUnsignedShort( position() );
  break;
case 4:
  dataLength = getInt( position() );
  break;
default:

代码示例来源: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: alibaba/tair-java-client

@Override
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) 
  throws Exception {
  final int origonPos = in.position();
  final int packetLength = in.remaining();
    in.position(origonPos);
    return false;
    in.position(origonPos);
    return false;

代码示例来源: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.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.server/mitosis

in.limit( in.position() + bodyLength );

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

logger.log(Level.FINEST,
  "partial message {0,number,#} bytes",
  msgBuf.position());

相关文章