java.lang.Object
org.klomp.snark.Request

class Requestextends Object
Holds all information needed for a partial piece request.

This class should be used only by PeerState, PeerConnectionIn, and PeerConnectionOut.

  • Field Details

    • piece

      private final PartialPiece piece
      The piece this request covers.
    • off

      final int off
      Offset in the piece.
    • len

      final int len
      Length in bytes.
    • sendTime

      long sendTime
      Send time.
  • Constructor Details

    • Request

      Request(PartialPiece piece, int off, int len)
      Creates a new Request.
      Parameters:
      piece - Piece number requested.
      off - the offset in the array.
      len - the number of bytes requested.
    • Request

      Request(PartialPiece piece, int off)
      Dummy Request for PeerState.returnPartialPieces(); len is zero.
      Parameters:
      piece - Piece number requested.
      off - the offset in the array.
  • Method Details

    • read

      public void read(DataInputStream din, BandwidthListener bwl) throws IOException
      Read from stream.
      Parameters:
      din - stream carrying the requested block data
      bwl - listener credited with the downloaded bytes
      Throws:
      IOException - if the stream ends early or the offset is not a block boundary
    • getPiece

      public int getPiece()
      The piece number this Request is for.
      Returns:
      the index of the piece this request covers
    • getPartialPiece

      public PartialPiece getPartialPiece()
      The PartialPiece this Request is for.
      Returns:
      the partial piece
    • hashCode

      public int hashCode()
      Hash based on piece number, offset, and length.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Two requests are equal if they share the same piece, offset, and length.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      A string representation of the request.
      Overrides:
      toString in class Object
      Returns:
      "(piece,off,len)" as the toString() form