class MagnetState extends Object
Nothing is synchronized here! Caller must synchronize on this for everything!
Reference: BEP 9
| Modifier and Type | Field and Description |
|---|---|
static int | CHUNK_SIZEChunk size for magnet metadata fetches (16 KB). |
| Constructor and Description |
|---|
MagnetState(byte[] iHash,
MetaInfo meta)Creates a new MagnetState for the given info hash. |
| Modifier and Type | Method and Description |
|---|---|
int | chunkSize(int chunk)Get the size of a specific chunk. |
int | chunksRemaining()Get the number of chunks remaining to be downloaded. |
byte[] | getChunk(int chunk)Get the data for a specific chunk. |
MetaInfo | getMetaInfo()Returns the MetaInfo for this magnet state. |
int | getNextRequest()Get the next chunk number to request. |
int | getSize()Returns the total metadata size in bytes. |
void | initialize(int size)Initializes the magnet state with the given metadata size. |
boolean | isComplete()Check if the magnet download is complete. |
boolean | isInitialized()Check if the magnet state has been initialized. |
boolean | saveChunk(int chunk,
byte[] data,
int off,
int length)Save a chunk of data to the magnet state. |
void | setMetaInfo(MetaInfo meta)Sets the MetaInfo for a completed magnet download. |
public static final int CHUNK_SIZE
public MagnetState(byte[] iHash,
MetaInfo meta)iHash - the 20-byte info hashmeta - the MetaInfo if already available, or null for a new magnet downloadpublic int chunkSize(int chunk)
chunk - the chunk numberpublic int chunksRemaining()
IllegalArgumentException - if not initializedpublic byte[] getChunk(int chunk)
chunk - the chunk number to retrieveIllegalArgumentException - if not complete or chunk number is invalidpublic MetaInfo getMetaInfo()
IllegalArgumentException - if not completepublic int getNextRequest()
IllegalArgumentException - if not initialized or completepublic int getSize()
IllegalArgumentException - if not initializedpublic void initialize(int size)
size - the metadata size in bytesIllegalArgumentException - if already initializedpublic boolean isComplete()
public boolean isInitialized()
public boolean saveChunk(int chunk,
byte[] data,
int off,
int length)
throws Exceptionchunk - the chunk number to savedata - the byte array containing the chunk dataoff - the offset in the data array where the chunk startslength - the lengthIllegalArgumentException - if not initialized, chunk number is invalid, or length is
incorrectException - if there's an error building the MetaInfopublic void setMetaInfo(MetaInfo meta)
meta - the completed MetaInfo