📄 show.java
字号:
protected String expandVariable( char variable, DownloadManager dm )
{
switch( variable )
{
case 'a':
return getShortStateString(dm.getState());
case 'c':
DecimalFormat df = new DecimalFormat("000.0%");
return df.format(dm.getStats().getCompleted() / 1000.0);
case 't':
if (dm.getState() == DownloadManager.STATE_ERROR)
return dm.getErrorDetails();
else {
if (dm.getDisplayName() == null)
return "?";
else
return dm.getDisplayName();
}
case 'z':
return DisplayFormatters.formatByteCountToKiBEtc(dm.getSize());
case 'e':
return DisplayFormatters.formatETA(dm.getStats().getETA());
case 'r':
long to = 0;
long tot = 0;
if (dm.getDiskManager() != null) {
DiskManagerFileInfo files[] = dm.getDiskManager().getFiles();
if (files != null) {
if (files.length>1) {
int c=0;
for (int i = 0; i < files.length; i++) {
if (files[i] != null) {
if (!files[i].isSkipped()) {
c += 1;
tot += files[i].getLength();
to += files[i].getDownloaded();
}
}
}
if (c == files.length)
tot = 0;
}
}
}
DecimalFormat df1 = new DecimalFormat("000.0%");
if (tot > 0) {
return " ("+df1.format(to * 1.0 / tot)+")";
} else
return "\t";
case 'd':
return DisplayFormatters.formatByteCountToKiBEtcPerSec(dm.getStats().getDataReceiveRate());
case 'u':
return DisplayFormatters.formatByteCountToKiBEtcPerSec(dm.getStats().getDataSendRate());
case 'D':
return DisplayFormatters.formatDownloaded(dm.getStats());
case 'U':
return DisplayFormatters.formatByteCountToKiBEtc(dm.getStats().getTotalDataBytesSent());
case 's':
return Integer.toString(dm.getNbSeeds());
case 'p':
return Integer.toString(dm.getNbPeers());
case 'v':
return Integer.toString(dm.getMaxUploads());
case 'I':
int downloadSpeed = dm.getStats().getDownloadRateLimitBytesPerSecond();
if( downloadSpeed <= 0 )
return "";
return "(max " + DisplayFormatters.formatByteCountToKiBEtcPerSec(downloadSpeed) + ")";
case 'O':
int uploadSpeed = dm.getStats().getUploadRateLimitBytesPerSecond();
if( uploadSpeed <= 0 )
return "";
return "(max " + DisplayFormatters.formatByteCountToKiBEtcPerSec(uploadSpeed) + ")";
case 'S':
case 'P':
TRTrackerScraperResponse hd = dm.getTrackerScrapeResponse();
if (hd == null || !hd.isValid())
return "?";
else
{
if( variable == 'S' )
return Integer.toString(hd.getSeeds());
else
return Integer.toString(hd.getPeers());
}
default:
return "??" + variable + "??";
}
}
/**
* returns the format string (in printf style format) to use for displaying the torrent summary
* @return
*/
protected String getDefaultSummaryFormat()
{
return "[%a] %c\t%t (%z) ETA: %e\r\n%r\tSpeed: %d%I / %u%O\tAmount: %D / %U\tConnections: %s(%S) / %p(%P)";
}
/**
* returns a string representation of the specified state number
* suitable for inclusion in a torrent summary
* @param dmstate
* @return
*/
private static String getShortStateString(int dmstate) {
switch( dmstate )
{
case DownloadManager.STATE_INITIALIZING:
return("I");
case DownloadManager.STATE_ALLOCATING:
return("A");
case DownloadManager.STATE_CHECKING:
return("C");
case DownloadManager.STATE_DOWNLOADING:
return(">");
case DownloadManager.STATE_ERROR:
return("E");
case DownloadManager.STATE_SEEDING:
return("*");
case DownloadManager.STATE_STOPPED:
return("!");
case DownloadManager.STATE_WAITING:
return(".");
case DownloadManager.STATE_READY:
return(":");
case DownloadManager.STATE_QUEUED:
return("-");
default:
return("?");
}
}
/**
* prints out the full details of a particular torrent
* @param out
* @param dm
* @param torrentNum
*/
private static void printTorrentDetails( PrintStream out, DownloadManager dm, int torrentNum, boolean verbose)
{
String name = dm.getDisplayName();
if (name == null)
name = "?";
out.println("> -----");
out.println("Info on Torrent #" + torrentNum + " (" + name + ")");
out.println("- General Info -");
String[] health = { "- no info -", "stopped", "no remote connections", "no tracker", "OK", "ko" };
try {
out.println("Health: " + health[dm.getHealthStatus()]);
} catch (Exception e) {
out.println("Health: " + health[0]);
}
out.println("State: " + Integer.toString(dm.getState()));
if (dm.getState() == DownloadManager.STATE_ERROR)
out.println("Error: " + dm.getErrorDetails());
out.println("Hash: " + TorrentUtils.nicePrintTorrentHash(dm.getTorrent(), true));
out.println("- Torrent file -");
out.println("Torrent Filename: " + dm.getTorrentFileName());
out.println("Saving to: " + dm.getSaveLocation());
out.println("Created By: " + dm.getTorrentCreatedBy());
out.println("Comment: " + dm.getTorrentComment());
out.println("- Tracker Info -");
TRTrackerAnnouncer trackerclient = dm.getTrackerClient();
if (trackerclient != null) {
out.println("URL: " + trackerclient.getTrackerUrl());
String timestr;
try {
int time = trackerclient.getTimeUntilNextUpdate();
if (time < 0) {
timestr = MessageText.getString("GeneralView.label.updatein.querying");
} else {
int minutes = time / 60;
int seconds = time % 60;
String strSeconds = "" + seconds;
if (seconds < 10) {
strSeconds = "0" + seconds; //$NON-NLS-1$
}
timestr = minutes + ":" + strSeconds;
}
} catch (Exception e) {
timestr = "unknown";
}
out.println("Time till next Update: " + timestr);
out.println("Status: " + trackerclient.getStatusString());
} else
out.println(" Not available");
out.println("- Files Info -");
DiskManagerFileInfo files[] = dm.getDiskManagerFileInfo();
if (files != null) {
for (int i = 0; i < files.length; i++) {
out.print(((i < 9) ? " " : " ") + Integer.toString(i + 1)
+ " (");
String tmp = ">";
if (files[i].isPriority())
tmp = "+";
if (files[i].isSkipped())
tmp = "!";
out.print(tmp + ") ");
if (files[i] != null) {
long fLen = files[i].getLength();
if (fLen > 0) {
DecimalFormat df = new DecimalFormat("000.0%");
out.print(df.format(files[i].getDownloaded() * 1.0
/ fLen));
out.println("\t" + files[i].getFile(true).getName());
} else
out.println("Info not available.");
} else
out.println("Info not available.");
}
} else
out.println(" Info not available.");
if ( verbose ){
out.println( "Pieces" );
PEPeerManager pm = dm.getPeerManager();
if ( pm != null ){
PiecePicker picker = pm.getPiecePicker();
PEPiece[] pieces = pm.getPieces();
String line = "";
for (int i=0;i<pieces.length;i++){
String str = picker.getPieceString( i );
line += (line.length()==0?(i + " "):",") + str;
PEPiece piece = pieces[i];
if ( piece != null ){
line += ":" + piece.getString();
}
if ( (i+1)%10 == 0 ){
out.println( line );
line = "";
}
}
if ( line.length() > 0 ){
out.println( line );
}
}
}
out.println("> -----");
}
protected void
showDHTStats(
ConsoleInput ci )
{
try{
PluginInterface def = ci.azureus_core.getPluginManager().getDefaultPluginInterface();
PluginInterface dht_pi =
def.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class );
if ( dht_pi == null ){
ci.out.println( "\tDHT isn't present" );
return;
}
DHTPlugin dht_plugin = (DHTPlugin)dht_pi.getPlugin();
if ( dht_plugin.getStatus() != DHTPlugin.STATUS_RUNNING ){
ci.out.println( "\tDHT isn't running yet (disabled or initialising)" );
return;
}
DHT[] dhts = dht_plugin.getDHTs();
for (int i=0;i<dhts.length;i++){
DHT dht = dhts[i];
DHTTransport transport = dht.getTransport();
DHTTransportStats t_stats = transport.getStats();
DHTDBStats d_stats = dht.getDataBase().getStats();
DHTControlStats c_stats = dht.getControl().getStats();
DHTRouterStats r_stats = dht.getRouter().getStats();
long[] rs = r_stats.getStats();
DHTNetworkPosition[] nps = transport.getLocalContact().getNetworkPositions();
String np_str = "";
for (int j=0;j<nps.length;j++){
np_str += (j==0?"":",") + nps[j];
}
ci.out.println( "DHT:ip=" + transport.getLocalContact().getAddress() +
",net=" + transport.getNetwork() +
",prot=V" + transport.getProtocolVersion() +
",np=" + np_str);
ci.out.println(
"Router" +
":nodes=" + rs[DHTRouterStats.ST_NODES] +
",leaves=" + rs[DHTRouterStats.ST_LEAVES] +
",contacts=" + rs[DHTRouterStats.ST_CONTACTS] +
",replacement=" + rs[DHTRouterStats.ST_REPLACEMENTS] +
",live=" + rs[DHTRouterStats.ST_CONTACTS_LIVE] +
",unknown=" + rs[DHTRouterStats.ST_CONTACTS_UNKNOWN] +
",failing=" + rs[DHTRouterStats.ST_CONTACTS_DEAD]);
ci.out.println(
"Transport" +
":" + t_stats.getString());
int[] dbv_details = d_stats.getValueDetails();
ci.out.println(
"Control:dht=" + c_stats.getEstimatedDHTSize() +
", Database:keys=" + d_stats.getKeyCount() +
",vals=" + dbv_details[DHTDBStats.VD_VALUE_COUNT]+
",loc=" + dbv_details[DHTDBStats.VD_LOCAL_SIZE]+
",dir=" + dbv_details[DHTDBStats.VD_DIRECT_SIZE]+
",ind=" + dbv_details[DHTDBStats.VD_INDIRECT_SIZE]+
",div_f=" + dbv_details[DHTDBStats.VD_DIV_FREQ]+
",div_s=" + dbv_details[DHTDBStats.VD_DIV_SIZE] );
}
}catch( Throwable e ){
e.printStackTrace( ci.out );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -