## 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 Summary
`static int` `CHUNK_SIZE`

Constructor Summary
`MagnetState(byte[] iHash, MetaInfo meta)`

Method Summary
`MetaInfo` `buildMetaInfo()`
`int` `chunkSize(int chunk)`
`int` `chunksRemaining()`
`byte[]` `getChunk(int chunk)`
`MetaInfo` `getMetaInfo()`
`int` `getNextRequest()`
`int` `getSize()`
`void` `initialize(int size)` Call this for a new magnet when you have the size
`boolean` `isComplete()`
`boolean` `isInitialized()`
`boolean` `saveChunk(int chunk, byte[] data, int off, int length)`
`void` `setMetaInfo(MetaInfo meta)` Call this for a new magnet when the download is complete.

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

Field Detail

### CHUNK_SIZE

    public static final int CHUNK_SIZE

See Also:
  Constant Field Values

Constructor Detail

### MagnetState

    public MagnetState(byte[] iHash,
                       MetaInfo meta)

Parameters:
  `meta` - null for new magnet

Method Detail

### initialize

    public void initialize(int size)

  Call this for a new magnet when you have the size

  Throws:
    `IllegalArgumentException`

### setMetaInfo

    public void setMetaInfo(MetaInfo meta)

  Call this for a new magnet when the download is complete.

  Throws:
    `IllegalArgumentException`

### getMetaInfo

    public MetaInfo getMetaInfo()

  Throws:
    `IllegalArgumentException`

### getSize

    public int getSize()

  Throws:
    `IllegalArgumentException`

### isInitialized

    public boolean isInitialized()

### isComplete

    public boolean isComplete()

### chunkSize

    public int chunkSize(int chunk)

### chunksRemaining

    public int chunksRemaining()

  Returns:
    chunk count

### getNextRequest

    public int getNextRequest()

  Returns:
    chunk number

### getChunk

    public byte[] getChunk(int chunk)

  Throws:
    `IllegalArgumentException`

### saveChunk

    public boolean saveChunk(int chunk,
                             byte[] data,
                             int off,
                             int length)
                      throws Exception

  Returns:
    true if this was the last piece
  Throws:
    `NPE,` - IllegalArgumentException, IOException, ...
    `Exception`

### buildMetaInfo

    public MetaInfo buildMetaInfo()
                           throws Exception

  Returns:
    true if this was the last piece
  Throws:
    `NPE,` - IllegalArgumentException, IOException, ...
    `Exception`