Mercurial > hg > Members > kono > jpf-core
comparison src/classes/gov/nasa/jpf/CachedROHttpConnection.java @ 0:61d41facf527
initial v8 import (history reset)
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 23 Jan 2015 10:14:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:61d41facf527 |
---|---|
1 /* | |
2 * Copyright (C) 2014, United States Government, as represented by the | |
3 * Administrator of the National Aeronautics and Space Administration. | |
4 * All rights reserved. | |
5 * | |
6 * The Java Pathfinder core (jpf-core) platform is licensed under the | |
7 * Apache License, Version 2.0 (the "License"); you may not use this file except | |
8 * in compliance with the License. You may obtain a copy of the License at | |
9 * | |
10 * http://www.apache.org/licenses/LICENSE-2.0. | |
11 * | |
12 * Unless required by applicable law or agreed to in writing, software | |
13 * distributed under the License is distributed on an "AS IS" BASIS, | |
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 * See the License for the specific language governing permissions and | |
16 * limitations under the License. | |
17 */ | |
18 | |
19 package gov.nasa.jpf; | |
20 | |
21 import java.io.ByteArrayInputStream; | |
22 import java.io.IOException; | |
23 import java.io.InputStream; | |
24 import java.net.Proxy; | |
25 import java.net.URL; | |
26 | |
27 import sun.net.www.protocol.http.Handler; | |
28 | |
29 /** | |
30 * this is just a very rough abstraction at this point, which only supports | |
31 * reading static URL contents. The data is cached for subsequent | |
32 * access, to avoid DOS by means of model checking | |
33 */ | |
34 public class CachedROHttpConnection extends java.net.HttpURLConnection { | |
35 | |
36 @Override | |
37 public void disconnect() { | |
38 //throw new UnsupportedOperationException("Not supported yet."); | |
39 } | |
40 | |
41 @Override | |
42 public boolean usingProxy() { | |
43 return false; | |
44 } | |
45 | |
46 @Override | |
47 public void connect() throws IOException { | |
48 //throw new UnsupportedOperationException("Not supported yet."); | |
49 } | |
50 | |
51 String host; | |
52 int port; | |
53 | |
54 public CachedROHttpConnection(URL u, String host, int port){ | |
55 super(u); | |
56 | |
57 this.host = host; | |
58 this.port = port; | |
59 } | |
60 | |
61 public CachedROHttpConnection(URL u, Proxy p, Handler handler){ | |
62 super(u); | |
63 } | |
64 | |
65 public CachedROHttpConnection(URL u, Proxy p) { | |
66 this (u, p, new Handler()); | |
67 } | |
68 | |
69 protected CachedROHttpConnection(URL u, Handler handler) throws IOException { | |
70 this(u, null, handler); | |
71 } | |
72 | |
73 | |
74 | |
75 private native byte[] getContents(String url); | |
76 | |
77 @Override | |
78 public synchronized InputStream getInputStream() throws IOException { | |
79 byte[] data = getContents(url.toString()); | |
80 return new ByteArrayInputStream(data); | |
81 } | |
82 | |
83 | |
84 } |