Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.klomp.snark
Class PartialPiece

    java.lang.Object
      org.klomp.snark.PartialPiece

All Implemented Interfaces:
  Comparable

     class PartialPiece

extends Object
implements Comparable

This is the class passed from PeerCoordinator to PeerState so PeerState may start requests. It is also passed from PeerState to PeerCoordinator when a piece is not completely downloaded, for example when the Peer disconnects or chokes.

Since:
  0.8.2

Constructor Summary
`PartialPiece(int piece, int len)` Used by PeerCoordinator.
`PartialPiece(Request firstOutstandingRequest)` Used by PeerState.

Method Summary
`int` | `compareTo(Object o)` Highest downloaded first
`boolean` | `equals(Object o)` Make this simple so PeerCoordinator can keep a List.
`long` | `getCreated()`
`int` | `getDownloaded()` how many bytes are good
`int` | `getPiece()` piece number
`Request` | `getRequest()` Convert this PartialPiece to a request for the next chunk.
`int` | `hashCode()`
`String` | `toString()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### PartialPiece

    public PartialPiece(int piece,
                        int len)
                 throws OutOfMemoryError

  Used by PeerCoordinator. Creates a new PartialPiece, with no chunks yet downloaded. Allocates the data.

  Parameters:
    `piece` - Piece number requested.
    `len` - must be equal to the piece length
  Throws:
    `OutOfMemoryError`

### PartialPiece

    public PartialPiece(Request firstOutstandingRequest)

  Used by PeerState. Creates a new PartialPiece, with chunks up to but not including firstOutstandingRequest already downloaded and stored in the Request byte array. Note that this cannot handle gaps; chunks after a missing chunk cannot be saved. That would be harder.

  Parameters:
    `firstOutstandingRequest` - the first request not fulfilled for the piece

Method Detail

### getRequest

    public Request getRequest()

  Convert this PartialPiece to a request for the next chunk. Used by PeerState only.

### getPiece

    public int getPiece()

  piece number

### getDownloaded

    public int getDownloaded()

  how many bytes are good

### getCreated

    public long getCreated()

### compareTo

    public int compareTo(Object o)
                  throws ClassCastException

  Highest downloaded first

  Specified by:
    `compareTo` in interface `Comparable`
  Throws:
    `ClassCastException`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### equals

    public boolean equals(Object o)

  Make this simple so PeerCoordinator can keep a List. Warning - compares piece number only!

  Overrides:
    `equals` in class `Object`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD