Package org.klomp.snark
Class MagnetState
- java.lang.Object
- 
- org.klomp.snark.MagnetState
 
- 
 class MagnetState extends Object Simple state for the download of the metainfo, shared between Peer and ExtensionHandler. Nothing is synchronized here! Caller must synchronize on this for everything! Reference: BEP 9- Since:
- 0.8.4 author zzz
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intCHUNK_SIZE
 - 
Constructor SummaryConstructors Constructor Description MagnetState(byte[] iHash, MetaInfo meta)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intchunkSize(int chunk)intchunksRemaining()byte[]getChunk(int chunk)MetaInfogetMetaInfo()intgetNextRequest()intgetSize()voidinitialize(int size)Call this for a new magnet when you have the sizebooleanisComplete()booleanisInitialized()booleansaveChunk(int chunk, byte[] data, int off, int length)voidsetMetaInfo(MetaInfo meta)Call this for a new magnet when the download is complete.
 
- 
- 
- 
Field Detail- 
CHUNK_SIZEpublic static final int CHUNK_SIZE - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
MagnetStatepublic MagnetState(byte[] iHash, MetaInfo meta)- Parameters:
- meta- null for new magnet
 
 
- 
 - 
Method Detail- 
initializepublic void initialize(int size) Call this for a new magnet when you have the size- Throws:
- IllegalArgumentException
 
 - 
setMetaInfopublic void setMetaInfo(MetaInfo meta) Call this for a new magnet when the download is complete.- Throws:
- IllegalArgumentException
 
 - 
getMetaInfopublic MetaInfo getMetaInfo() - Throws:
- IllegalArgumentException
 
 - 
getSizepublic int getSize() - Throws:
- IllegalArgumentException
 
 - 
isInitializedpublic boolean isInitialized() 
 - 
isCompletepublic boolean isComplete() 
 - 
chunkSizepublic int chunkSize(int chunk) 
 - 
chunksRemainingpublic int chunksRemaining() - Returns:
- chunk count
 
 - 
getNextRequestpublic int getNextRequest() - Returns:
- chunk number
 
 - 
getChunkpublic byte[] getChunk(int chunk) - Throws:
- IllegalArgumentException
 
 - 
saveChunkpublic boolean saveChunk(int chunk, byte[] data, int off, int length) throws Exception- Returns:
- true if this was the last piece
- Throws:
- NullPointerException- IllegalArgumentException, IOException, ...
- Exception
 
 
- 
 
-