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_SIZE |
| Constructor and Description |
|---|
MagnetState(byte[] iHash,
MetaInfo meta) |
| 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() |
int |
getNextRequest()
Get the next chunk number to request.
|
int |
getSize() |
void |
initialize(int size)
Call this for a new magnet when you have the 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)
Call this for a new magnet when the download is complete.
|
public static final int CHUNK_SIZE
public MagnetState(byte[] iHash,
MetaInfo meta)
meta - null for new magnetpublic 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()
IllegalArgumentExceptionpublic int getNextRequest()
IllegalArgumentException - if not initialized or completepublic int getSize()
IllegalArgumentExceptionpublic void initialize(int size)
IllegalArgumentExceptionpublic boolean isComplete()
public boolean isInitialized()
public boolean saveChunk(int chunk,
byte[] data,
int off,
int length)
throws Exception
chunk - the chunk number to savedata - the byte array containing the chunk dataoff - the offset in the data array where the chunk startslength - the length of the chunk dataIllegalArgumentException - if not initialized, chunk number is invalid, or length is
incorrectException - if there's an error building the MetaInfopublic void setMetaInfo(MetaInfo meta)
IllegalArgumentException