FileDocCategorySizeDatePackage
BTPiece.javaAPI DocAzureus 3.0.3.44043Sun Mar 04 21:08:16 GMT 2007com.aelitis.azureus.core.peermanager.messaging.bittorrent

BTPiece

public class BTPiece extends Object implements BTMessage
BitTorrent piece message.

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

  
  
             
    this.piece_number = piece_number;
    this.piece_offset = piece_offset;
    this.piece_length = data == null ? 0 : data.remaining( DirectByteBuffer.SS_MSG );
    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 ) < 8 ) {
      throw new MessageException( "[" +getID()+ "] decode error: payload.remaining[" +data.remaining( DirectByteBuffer.SS_MSG )+ "] < 8" );
    }
    
    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 BTPiece( 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_BT_PIECE, 8 );
      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 = BTMessage.ID_BT_PIECE + " data for piece #" + piece_number + ":" + piece_offset + "->" + (piece_offset + piece_length -1);
    }
    
    return description;
  
public java.lang.StringgetFeatureID()

  return BTMessage.BT_FEATURE_ID;  
public intgetFeatureSubID()

  return BTMessage.SUBID_BT_PIECE;  
public java.lang.StringgetID()

  return BTMessage.ID_BT_PIECE;  
public byte[]getIDBytes()

  return BTMessage.ID_BT_PIECE_BYTES;  
public DirectByteBuffergetPieceData()

  return buffer[1];  
public intgetPieceNumber()

  return piece_number;  
public intgetPieceOffset()

  return piece_offset;  
public intgetType()

  return Message.TYPE_DATA_PAYLOAD;  
public bytegetVersion()

 return version;