Package org.klomp.snark
Class PartialPiece
java.lang.Object
org.klomp.snark.PartialPiece
- All Implemented Interfaces:
Comparable<PartialPiece>
Store the received data either on the heap or in a temp file.
The third option, to write chunks directly to the destination file,
is unimplemented.
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.
New objects for the same piece are created during the end game -
this object should not be shared among multiple peers.
- Since:
- 0.8.2
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(PartialPiece opp) boolean
Make this simple so PeerCoordinator can keep a List.int
How many bytes are good - as set by read().byte[]
getHash()
Piece must be complete.int
int
getPiece()
piece numberConvert this PartialPiece to a request for the next chunk.boolean
hasChunk
(int chunk) Has this chunk been downloaded?boolean
hasData()
Have any chunks been downloaded?int
hashCode()
boolean
void
read
(DataInputStream din, int offset, int len, BandwidthListener bwl) Blocking.void
release()
Release all resources.toString()
static void
void
write
(DataOutput out, int offset, int len) Piece must be complete.
-
Constructor Details
-
PartialPiece
Used by PeerCoordinator. Creates a new PartialPiece, with no chunks yet downloaded. Allocates the data storage area, either on the heap or in the temp directory, depending on size.- Parameters:
piece
- Piece number requested.len
- must be equal to the piece length
-
-
Method Details
-
getRequest
Convert this PartialPiece to a request for the next chunk. Used by PeerState only.- Returns:
- null if complete
-
getPiece
public int getPiece()piece number -
getLength
public int getLength()- Since:
- 0.9.1
-
isComplete
public boolean isComplete()- Since:
- 0.9.62
-
hasData
public boolean hasData()Have any chunks been downloaded?- Since:
- 0.9.63
-
hasChunk
public boolean hasChunk(int chunk) Has this chunk been downloaded?- Since:
- 0.9.63
-
getDownloaded
public int getDownloaded()How many bytes are good - as set by read(). As of 0.9.63, accurately counts good bytes after "holes". -
getHash
Piece must be complete. The SHA1 hash of the completely read data.- Throws:
IOException
- Since:
- 0.9.1
-
read
public void read(DataInputStream din, int offset, int len, BandwidthListener bwl) throws IOException Blocking. If offset matches the previous downloaded amount (as set by a previous call to read() or setDownlaoded()), the downloaded amount will be incremented by len.- Throws:
IOException
- Since:
- 0.9.1
-
write
Piece must be complete. Caller must synchronize on out and seek to starting point. Caller must call release() when done with the whole piece.- Parameters:
out
- stream to write tooffset
- offset in the piecelen
- length to write- Throws:
IOException
- Since:
- 0.9.1
-
release
public void release()Release all resources.- Since:
- 0.9.1
-
compareTo
- Specified by:
compareTo
in interfaceComparable<PartialPiece>
-
hashCode
public int hashCode() -
equals
Make this simple so PeerCoordinator can keep a List. Warning - compares piece number only! -
toString
-
warn
- Since:
- 0.9.62
-