|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.net; |
|
|
|
import java.util.ArrayList; |
|
import java.util.Iterator; |
|
import java.net.URL; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class ProgressMonitor |
|
{ |
|
|
|
|
|
*/ |
|
public static synchronized ProgressMonitor getDefault() { |
|
return pm; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public static synchronized void setDefault(ProgressMonitor m) { |
|
if (m != null) |
|
pm = m; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public static synchronized void setMeteringPolicy(ProgressMeteringPolicy policy) { |
|
if (policy != null) |
|
meteringPolicy = policy; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public ArrayList<ProgressSource> getProgressSources() { |
|
ArrayList<ProgressSource> snapshot = new ArrayList<>(); |
|
|
|
try { |
|
synchronized(progressSourceList) { |
|
for (Iterator<ProgressSource> iter = progressSourceList.iterator(); iter.hasNext();) { |
|
ProgressSource pi = iter.next(); |
|
|
|
|
|
snapshot.add((ProgressSource)pi.clone()); |
|
} |
|
} |
|
} |
|
catch(CloneNotSupportedException e) { |
|
e.printStackTrace(); |
|
} |
|
|
|
return snapshot; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public synchronized int getProgressUpdateThreshold() { |
|
return meteringPolicy.getProgressUpdateThreshold(); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean shouldMeterInput(URL url, String method) { |
|
return meteringPolicy.shouldMeterInput(url, method); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void registerSource(ProgressSource pi) { |
|
|
|
synchronized(progressSourceList) { |
|
if (progressSourceList.contains(pi)) |
|
return; |
|
|
|
progressSourceList.add(pi); |
|
} |
|
|
|
|
|
if (progressListenerList.size() > 0) |
|
{ |
|
|
|
ArrayList<ProgressListener> listeners = new ArrayList<>(); |
|
|
|
|
|
synchronized(progressListenerList) { |
|
for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) { |
|
listeners.add(iter.next()); |
|
} |
|
} |
|
|
|
|
|
for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) { |
|
ProgressListener pl = iter.next(); |
|
ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected()); |
|
pl.progressStart(pe); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void unregisterSource(ProgressSource pi) { |
|
|
|
synchronized(progressSourceList) { |
|
|
|
if (progressSourceList.contains(pi) == false) |
|
return; |
|
|
|
|
|
pi.close(); |
|
progressSourceList.remove(pi); |
|
} |
|
|
|
|
|
if (progressListenerList.size() > 0) |
|
{ |
|
|
|
ArrayList<ProgressListener> listeners = new ArrayList<>(); |
|
|
|
|
|
synchronized(progressListenerList) { |
|
for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) { |
|
listeners.add(iter.next()); |
|
} |
|
} |
|
|
|
|
|
for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) { |
|
ProgressListener pl = iter.next(); |
|
ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected()); |
|
pl.progressFinish(pe); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void updateProgress(ProgressSource pi) { |
|
|
|
synchronized (progressSourceList) { |
|
if (progressSourceList.contains(pi) == false) |
|
return; |
|
} |
|
|
|
|
|
if (progressListenerList.size() > 0) |
|
{ |
|
|
|
ArrayList<ProgressListener> listeners = new ArrayList<>(); |
|
|
|
|
|
synchronized(progressListenerList) { |
|
for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) { |
|
listeners.add(iter.next()); |
|
} |
|
} |
|
|
|
|
|
for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) { |
|
ProgressListener pl = iter.next(); |
|
ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected()); |
|
pl.progressUpdate(pe); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void addProgressListener(ProgressListener l) { |
|
synchronized(progressListenerList) { |
|
progressListenerList.add(l); |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void removeProgressListener(ProgressListener l) { |
|
synchronized(progressListenerList) { |
|
progressListenerList.remove(l); |
|
} |
|
} |
|
|
|
|
|
private static ProgressMeteringPolicy meteringPolicy = new DefaultProgressMeteringPolicy(); |
|
|
|
|
|
private static ProgressMonitor pm = new ProgressMonitor(); |
|
|
|
|
|
private ArrayList<ProgressSource> progressSourceList = new ArrayList<ProgressSource>(); |
|
|
|
|
|
private ArrayList<ProgressListener> progressListenerList = new ArrayList<ProgressListener>(); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
class DefaultProgressMeteringPolicy implements ProgressMeteringPolicy { |
|
|
|
|
|
*/ |
|
public boolean shouldMeterInput(URL url, String method) |
|
{ |
|
// By default, no URL input stream is metered for |
|
|
|
return false; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public int getProgressUpdateThreshold() { |
|
|
|
return 8192; |
|
} |
|
} |