/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the overall rate of bytes/second over all transfers for all watchers. */ public static double calculateOverallBytesPerSecond(BytesProgressWatcher[] progressWatchers) { long initialStartTime = Long.MAX_VALUE; // The oldest start time of any monitor. long bytesTotal = 0; for (int i = 0; i < progressWatchers.length; i++) { // Ignore any watchers that have not yet started. if (!progressWatchers[i].isStarted()) { continue; } // Add up all the bytes transferred by all started watchers. bytesTotal += progressWatchers[i].getTotalBytesInAllTransfers(); // Find the earliest starting time of any monitor. if (progressWatchers[i].getHistoricStartTimeMS() < initialStartTime) { initialStartTime = progressWatchers[i].getHistoricStartTimeMS(); } } // Determine how much time has elapsed since the earliest watcher start time. long elapsedTimeSecs = (System.currentTimeMillis() - initialStartTime) / 1000; // Calculate the overall rate of bytes/second over all transfers for all watchers. double bytesPerSecondOverall = (elapsedTimeSecs == 0 ? bytesTotal : (double)bytesTotal / elapsedTimeSecs); return bytesPerSecondOverall; }
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the overall rate of bytes/second over all transfers for all watchers. */ public static double calculateOverallBytesPerSecond(BytesProgressWatcher[] progressWatchers) { long initialStartTime = Long.MAX_VALUE; // The oldest start time of any monitor. long bytesTotal = 0; for (int i = 0; i < progressWatchers.length; i++) { // Ignore any watchers that have not yet started. if (!progressWatchers[i].isStarted()) { continue; } // Add up all the bytes transferred by all started watchers. bytesTotal += progressWatchers[i].getTotalBytesInAllTransfers(); // Find the earliest starting time of any monitor. if (progressWatchers[i].getHistoricStartTimeMS() < initialStartTime) { initialStartTime = progressWatchers[i].getHistoricStartTimeMS(); } } // Determine how much time has elapsed since the earliest watcher start time. long elapsedTimeSecs = (System.currentTimeMillis() - initialStartTime) / 1000; // Calculate the overall rate of bytes/second over all transfers for all watchers. double bytesPerSecondOverall = (elapsedTimeSecs == 0 ? bytesTotal : (double)bytesTotal / elapsedTimeSecs); return bytesPerSecondOverall; }