Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.klomp.snark
Class MetaInfo

    java.lang.Object
      org.klomp.snark.MetaInfo

    public class MetaInfo

extends Object

Note: this class is buggy, as it doesn't propogate custom meta fields into the bencoded info data, and from there to the info_hash. At the moment, though, it seems to work with torrents created by I2P-BT, I2PRufus and Azureus.

Constructor Summary
`MetaInfo(BDecoder be)` Creates a new MetaInfo from the given BDecoder.
`MetaInfo(InputStream in)` Creates a new MetaInfo from the given InputStream.
`MetaInfo(Map m)` Creates a new MetaInfo from a Map of BEValues and the SHA1 over the original bencoded info dictonary (this is a hack, we could reconstruct the bencoded stream and recalculate the hash).
`MetaInfo(String announce, String name, String name_utf8, List files, List lengths, int piece_length, byte[] piece_hashes, long length)`

Method Summary
`boolean` | `checkPiece(int piece, byte[] bs, int off, int length)` Checks that the given piece has the same SHA1 hash as the given byte array.
`String` | `getAnnounce()` Returns the string representing the URL of the tracker for this torrent.
`List` | `getFiles()` Returns a list of lists of file name hierarchies or null if it is a single name.
`byte[]` | `getInfoHash()` Returns the original 20 byte SHA1 hash over the bencoded info map.
`List` | `getLengths()` Returns a list of Longs indication the size of the individual files, or null if it is a single file.
`String` | `getName()` Returns the requested name for the file or toplevel directory.
`(package private) byte[]` | `getPieceHashes()` Returns the piece hashes.
`int` | `getPieceLength(int piece)` Return the length of a piece.
`int` | `getPieces()` Returns the number of pieces.
`byte[]` | `getTorrentData()`
`long` | `getTotalLength()` Returns the total length of the torrent in bytes.
`MetaInfo` | `reannounce(String announce)` Creates a copy of this MetaInfo that shares everything except the announce URL.
`String` | `toString()`

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

Constructor Detail

### MetaInfo

    MetaInfo(String announce,
             String name,
             String name_utf8,
             List files,
             List lengths,
             int piece_length,
             byte[] piece_hashes,
             long length)

### MetaInfo

    public MetaInfo(InputStream in)
             throws IOException

  Creates a new MetaInfo from the given InputStream. The InputStream must start with a correctly bencoded dictonary describing the torrent.

  Throws:
    `IOException`

### MetaInfo

    public MetaInfo(BDecoder be)
             throws IOException

  Creates a new MetaInfo from the given BDecoder. The BDecoder must have a complete dictionary describing the torrent.

  Throws:
    `IOException`

### MetaInfo

    public MetaInfo(Map m)
             throws InvalidBEncodingException

  Creates a new MetaInfo from a Map of BEValues and the SHA1 over the original bencoded info dictonary (this is a hack, we could reconstruct the bencoded stream and recalculate the hash). Will throw a InvalidBEncodingException if the given map does not contain a valid announce string or info dictonary.

  Throws:
    `InvalidBEncodingException`

Method Detail

### getAnnounce

    public String getAnnounce()

  Returns the string representing the URL of the tracker for this torrent.

### getInfoHash

    public byte[] getInfoHash()

  Returns the original 20 byte SHA1 hash over the bencoded info map.

### getPieceHashes

    byte[] getPieceHashes()

  Returns the piece hashes. Only used by storage so package local.

### getName

    public String getName()

  Returns the requested name for the file or toplevel directory. If it is a toplevel directory name getFiles() will return a non-null List of file name hierarchy name.

### getFiles

    public List getFiles()

  Returns a list of lists of file name hierarchies or null if it is a single name. It has the same size as the list returned by getLengths().

### getLengths

    public List getLengths()

  Returns a list of Longs indication the size of the individual files, or null if it is a single file. It has the same size as the list returned by getFiles().

### getPieces

    public int getPieces()

  Returns the number of pieces.

### getPieceLength

    public int getPieceLength(int piece)

  Return the length of a piece. All pieces are of equal length except for the last one (`getPieces()-1`).

  Throws:
    `IndexOutOfBoundsException` - when piece is equal to or greater then the number of pieces in the torrent.

### checkPiece

    public boolean checkPiece(int piece,
                              byte[] bs,
                              int off,
                              int length)

  Checks that the given piece has the same SHA1 hash as the given byte array. Returns random results or IndexOutOfBoundsExceptions when the piece number is unknown.

### getTotalLength

    public long getTotalLength()

  Returns the total length of the torrent in bytes.

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### reannounce

    public MetaInfo reannounce(String announce)

  Creates a copy of this MetaInfo that shares everything except the announce URL.

### getTorrentData

    public byte[] getTorrentData()

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD