Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java
41154 views
1
/*
2
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 4333920 4994372
27
* @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem
28
* @modules java.base/sun.net
29
* jdk.httpserver
30
* @library /test/lib
31
* @run main ChunkedEncodingWithProgressMonitorTest
32
*/
33
34
import java.net.*;
35
import java.util.BitSet;
36
import sun.net.ProgressMeteringPolicy;
37
import sun.net.ProgressMonitor;
38
import sun.net.ProgressListener;
39
import sun.net.ProgressEvent;
40
41
public class ChunkedEncodingWithProgressMonitorTest {
42
public static void main (String[] args) throws Exception {
43
ProgressMonitor.setMeteringPolicy(new MyProgressMeteringPolicy());
44
ProgressListener listener = new MyProgressListener();
45
ProgressMonitor.getDefault().addProgressListener(listener);
46
ChunkedEncodingTest.test();
47
ProgressMonitor.getDefault().removeProgressListener(listener);
48
49
if (flag.cardinality() != 3) {
50
throw new RuntimeException("All three methods in ProgressListener"+
51
" should be called. Yet the number of"+
52
" methods actually called are "+
53
flag.cardinality());
54
}
55
}
56
57
static class MyProgressMeteringPolicy implements ProgressMeteringPolicy {
58
/**
59
* Return true if metering should be turned on for a particular network input stream.
60
*/
61
public boolean shouldMeterInput(URL url, String method) {
62
return true;
63
}
64
65
/**
66
* Return update notification threshold.
67
*/
68
public int getProgressUpdateThreshold() {
69
return 8192;
70
}
71
}
72
73
static BitSet flag = new BitSet(3);
74
75
static class MyProgressListener implements ProgressListener {
76
/**
77
* Start progress.
78
*/
79
public void progressStart(ProgressEvent evt) {
80
System.out.println("start: received progressevent "+evt);
81
if (flag.nextSetBit(0) == -1)
82
flag.set(0);
83
}
84
85
/**
86
* Update progress.
87
*/
88
public void progressUpdate(ProgressEvent evt) {
89
System.out.println("update: received progressevent "+evt);
90
if (flag.nextSetBit(1) == -1)
91
flag.set(1);
92
}
93
94
/**
95
* Finish progress.
96
*/
97
public void progressFinish(ProgressEvent evt) {
98
System.out.println("finish: received progressevent "+evt);
99
if (flag.nextSetBit(2) == -1)
100
flag.set(2);
101
}
102
}
103
}
104
105