FileDocCategorySizeDatePackage
AZSessionPiece.javaAPI DocAzureus 3.0.3.44484Sun Mar 04 21:08:16 GMT 2007com.aelitis.azureus.core.peermanager.messaging.azureus.session

AZSessionPiece

public class AZSessionPiece extends Object implements com.aelitis.azureus.core.peermanager.messaging.azureus.AZMessage
BitTorrent piece message.

Fields Summary
private final byte
version
private final DirectByteBuffer[]
buffer
private String
description
private final int
session_id
private final int
piece_number
private final int
piece_offset
private final int
piece_length
Constructors Summary
public AZSessionPiece(int session_id, int piece_number, int piece_offset, DirectByteBuffer data, byte version)

  
  
               
    this.session_id = session_id;
    this.piece_number = piece_number;
    this.piece_offset = piece_offset;
    this.piece_length = data == null ? 0 : data.remaining( DirectByteBuffer.SS_BT );
    buffer[1] = data;
    this.version = version;
  
Methods Summary
public com.aelitis.azureus.core.peermanager.messaging.Messagedeserialize(DirectByteBuffer data, byte version)

    
    if( data == null ) {
      throw new MessageException( "[" +getID() + "] decode error: data == null" );
    }
    
    if( data.remaining( DirectByteBuffer.SS_MSG ) < 12 ) {
      throw new MessageException( "[" +getID() + "] decode error: payload.remaining[" +data.remaining( DirectByteBuffer.SS_MSG )+ "] < 12" );
    }
    
    
    int id = data.getInt( DirectByteBuffer.SS_MSG );
    
    int number = data.getInt( DirectByteBuffer.SS_MSG );
    if( number < 0 ) {
      throw new MessageException( "[" +getID() + "] decode error: number < 0" );
    }
    
    int offset = data.getInt( DirectByteBuffer.SS_MSG );
    if( offset < 0 ) {
      throw new MessageException( "[" +getID() + "] decode error: offset < 0" );
    }
    
    return new AZSessionPiece( id, number, offset, data, version );
  
public voiddestroy()

    if( buffer[0] != null ) buffer[0].returnToPool();
    if( buffer[1] != null ) buffer[1].returnToPool();
  
public DirectByteBuffer[]getData()

    if( buffer[0] == null ) {
      buffer[0] = DirectByteBufferPool.getBuffer( DirectByteBuffer.AL_MSG, 12 );
      buffer[0].putInt( DirectByteBuffer.SS_MSG, session_id );
      buffer[0].putInt( DirectByteBuffer.SS_MSG, piece_number );
      buffer[0].putInt( DirectByteBuffer.SS_MSG, piece_offset );
      buffer[0].flip( DirectByteBuffer.SS_MSG );
    }
    
    return buffer;
  
public java.lang.StringgetDescription()

    if( description == null ) {
      description = getID()+ " session #" +session_id+ " data for piece #" + piece_number + ":" + piece_offset + "->" + (piece_offset + piece_length -1);
    }
    
    return description;
  
public java.lang.StringgetFeatureID()

  throw new RuntimeException( "not implemented" );  
public intgetFeatureSubID()

  throw new RuntimeException( "not implemented" );  
public java.lang.StringgetID()

  return AZMessage.ID_AZ_SESSION_PIECE;  
public byte[]getIDBytes()

  return AZMessage.ID_AZ_SESSION_PIECE_BYTES;  
public DirectByteBuffergetPieceData()

  return buffer[1];  
public intgetPieceNumber()

  return piece_number;  
public intgetPieceOffset()

  return piece_offset;  
public intgetSessionID()

  return session_id;  
public intgetType()

  return Message.TYPE_DATA_PAYLOAD;  
public bytegetVersion()

 return version;