src/java.base/share/classes/sun/net/ProgressMonitor.java
author chegar
Fri, 18 Oct 2019 21:25:01 +0100
branchdatagramsocketimpl-branch
changeset 58697 e3ff12d14d43
parent 47216 71c04702a3d5
permissions -rw-r--r--
datagramsocketimpl-branch: minor refactoring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * ProgressMonitor is a class for monitoring progress in network input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author Stanley Man-Kit Ho
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class ProgressMonitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * Return default ProgressMonitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static synchronized ProgressMonitor getDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        return pm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Change default ProgressMonitor implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static synchronized void setDefault(ProgressMonitor m)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        if (m != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            pm = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Change progress metering policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static synchronized void setMeteringPolicy(ProgressMeteringPolicy policy)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        if (policy != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            meteringPolicy = policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Return a snapshot of the ProgressSource list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public ArrayList<ProgressSource> getProgressSources()    {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
    67
        ArrayList<ProgressSource> snapshot = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            synchronized(progressSourceList)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                for (Iterator<ProgressSource> iter = progressSourceList.iterator(); iter.hasNext();)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    ProgressSource pi = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    // Clone ProgressSource and add to snapshot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    snapshot.add((ProgressSource)pi.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        catch(CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return snapshot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Return update notification threshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public synchronized int getProgressUpdateThreshold()    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return meteringPolicy.getProgressUpdateThreshold();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Return true if metering should be turned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * for a particular URL input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public boolean shouldMeterInput(URL url, String method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return meteringPolicy.shouldMeterInput(url, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Register progress source when progress is began.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public void registerSource(ProgressSource pi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        synchronized(progressSourceList)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            if (progressSourceList.contains(pi))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            progressSourceList.add(pi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // Notify only if there is at least one listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (progressListenerList.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            // Notify progress listener if there is progress change
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   117
            ArrayList<ProgressListener> listeners = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            // Copy progress listeners to another list to avoid holding locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            synchronized(progressListenerList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    listeners.add(iter.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            // Fire event on each progress listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                ProgressListener pl = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                pl.progressStart(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Unregister progress source when progress is finished.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void unregisterSource(ProgressSource pi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        synchronized(progressSourceList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            // Return if ProgressEvent does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            if (progressSourceList.contains(pi) == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            // Close entry and remove from map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            pi.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            progressSourceList.remove(pi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // Notify only if there is at least one listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (progressListenerList.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            // Notify progress listener if there is progress change
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   154
            ArrayList<ProgressListener> listeners = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // Copy progress listeners to another list to avoid holding locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            synchronized(progressListenerList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    listeners.add(iter.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            // Fire event on each progress listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                ProgressListener pl = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                pl.progressFinish(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Progress source is updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void updateProgress(ProgressSource pi)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        synchronized (progressSourceList)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (progressSourceList.contains(pi) == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Notify only if there is at least one listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (progressListenerList.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            // Notify progress listener if there is progress change
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   186
            ArrayList<ProgressListener> listeners = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // Copy progress listeners to another list to avoid holding locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            synchronized(progressListenerList)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                for (Iterator<ProgressListener> iter = progressListenerList.iterator(); iter.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    listeners.add(iter.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            // Fire event on each progress listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            for (Iterator<ProgressListener> iter = listeners.iterator(); iter.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                ProgressListener pl = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                ProgressEvent pe = new ProgressEvent(pi, pi.getURL(), pi.getMethod(), pi.getContentType(), pi.getState(), pi.getProgress(), pi.getExpected());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                pl.progressUpdate(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Add progress listener in progress monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public void addProgressListener(ProgressListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        synchronized(progressListenerList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            progressListenerList.add(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Remove progress listener from progress monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void removeProgressListener(ProgressListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        synchronized(progressListenerList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            progressListenerList.remove(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    // Metering policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private static ProgressMeteringPolicy meteringPolicy = new DefaultProgressMeteringPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    // Default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private static ProgressMonitor pm = new ProgressMonitor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    // ArrayList for outstanding progress sources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    private ArrayList<ProgressSource> progressSourceList = new ArrayList<ProgressSource>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    // ArrayList for progress listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private ArrayList<ProgressListener> progressListenerList = new ArrayList<ProgressListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * Default progress metering policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
class DefaultProgressMeteringPolicy implements ProgressMeteringPolicy  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Return true if metering should be turned on for a particular network input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public boolean shouldMeterInput(URL url, String method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // By default, no URL input stream is metered for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // performance reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Return update notification threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public int getProgressUpdateThreshold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        // 8K - same as default I/O buffer size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return 8192;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}