-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathURLConnectionReuseConnection.java
More file actions
57 lines (42 loc) · 1.77 KB
/
Copy pathURLConnectionReuseConnection.java
File metadata and controls
57 lines (42 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import specification.Borrowed;
import specification.Unique;
public class SSSURLConnectionReuseConnection {
public static void example4278917(@Borrowed URL address) {
try {
// Step 1) Open the connection
URLConnection connection = address.openConnection(); // returns a unique object
// Step 2) Connect
connection.connect();
/* Other code in original question */
// Step 3) Setup parameters and connection properties after connection == ERROR
connection.setAllowUserInteraction(true);
connection.addRequestProperty("AUTHENTICATION_REQUEST_PROPERTY", "authorizationRequest");
connection.getHeaderFields();
} catch (IOException e) {
// Handle exceptions related to network or stream issues
System.err.println("Error: " + e.getMessage());
}
}
}
class URL{
@Unique // @StateRefinement (return, to="manipulate")
public URLConnection openConnection() {
return new URLConnection();
}
}
/**
* --- openConnection() ----> [MANIPULATE PARAMS] ------> connect() -----> [INTERACT]
* setAllowUserInteraction() getContent()
* addRequestProperty()... getHeaderFields()...
*/
// @StateSet({"manipulate", "interact"})
class URLConnection{
//@StateRefinement(this, from="manipulate")
void setAllowUserInteraction(boolean b){}
//@StateRefinement(this, from="manipulate")
void addRequestProperty(String s1, String s2){}
//@StateRefinement(this, from="interact")
void getHeaderFields(){}
//@StateRefinement(this, from="manipulate", to="interact")
void connect() throws IOException {}
}