Interface TorrentBuilder.Listener
- Enclosing class:
TorrentBuilder
Listener allows applications to filter files during torrent creation and
track hash computation progress. Implement this interface to customize which files
are included in the torrent and display progress to the user.
File Filtering:
The accept() method is called for every file encountered during directory
traversal. Return true to include the file, false to skip it. This is useful for
excluding temporary files, hidden files, or other unwanted data.
Progress Tracking:
The progress() method is called as each piece's hash is computed, enabling
progress bars or status updates during the potentially time-consuming hashing phase.
Usage Example:
TorrentBuilder.Listener listener = new TorrentBuilder.Listener() {
public boolean accept(String filename) {
// Skip hidden files and system files
if (filename.startsWith(\".\")) return false;
if (filename.equals(\"Thumbs.db\")) return false;
if (filename.equals(\"Desktop.ini\")) return false;
return true;
}
public void progress(int pieceIndex, int numPieces) {
// Display progress
double percent = (double) pieceIndex / numPieces * 100;
System.out.println(String.format(\"Hashing: %.0f%% (%d/%d pieces)\",
percent, pieceIndex, numPieces));
}
};
TorrentBuilder builder = new TorrentBuilder();
builder.listener(listener);
-
Method Summary
-
Method Details
-
accept
Called during directory traversal to filter files.Return true to include the file in the torrent, false to skip it.
- Parameters:
filename- the filename being considered- Returns:
- true to include, false to skip
-
progress
void progress(int pieceIndex, int numPieces) Called periodically during hash computation.Use this to update progress bars or status displays.
- Parameters:
pieceIndex- the current piece being hashed (0-based)numPieces- the total number of pieces
-