24 */
25
26 /**
27 * Open an file input stream given a URL.
28 * @author James Gosling
29 * @author Steven B. Byrne
30 */
31
32 package sun.net.www.protocol.file;
33
34 import java.net.URL;
35 import java.net.FileNameMap;
36 import java.io.*;
37 import java.text.Collator;
38 import java.security.Permission;
39 import sun.net.*;
40 import sun.net.www.*;
41 import java.util.*;
42 import java.text.SimpleDateFormat;
43
44 import sun.security.action.GetPropertyAction;
45 import sun.security.action.GetIntegerAction;
46 import sun.security.action.GetBooleanAction;
47
48 public class FileURLConnection extends URLConnection {
49
50 static String CONTENT_LENGTH = "content-length";
51 static String CONTENT_TYPE = "content-type";
52 static String TEXT_PLAIN = "text/plain";
53 static String LAST_MODIFIED = "last-modified";
54
55 String contentType;
56 InputStream is;
57
58 File file;
59 String filename;
60 boolean isDirectory = false;
61 boolean exists = false;
62 List<String> files;
63
64 long length = -1;
65 long lastModified = 0;
66
67 protected FileURLConnection(URL u, File file) {
207 // Put it into a (default) locale-specific byte-stream.
208 is = new ByteArrayInputStream(sb.toString().getBytes());
209 } else {
210 throw new FileNotFoundException(filename);
211 }
212 }
213 return is;
214 }
215
216 Permission permission;
217
218 /* since getOutputStream isn't supported, only read permission is
219 * relevant
220 */
221 public Permission getPermission() throws IOException {
222 if (permission == null) {
223 String decodedPath = ParseUtil.decode(url.getPath());
224 if (File.separatorChar == '/') {
225 permission = new FilePermission(decodedPath, "read");
226 } else {
227 permission = new FilePermission(
228 decodedPath.replace('/',File.separatorChar), "read");
229 }
230 }
231 return permission;
232 }
233 }
|
24 */
25
26 /**
27 * Open an file input stream given a URL.
28 * @author James Gosling
29 * @author Steven B. Byrne
30 */
31
32 package sun.net.www.protocol.file;
33
34 import java.net.URL;
35 import java.net.FileNameMap;
36 import java.io.*;
37 import java.text.Collator;
38 import java.security.Permission;
39 import sun.net.*;
40 import sun.net.www.*;
41 import java.util.*;
42 import java.text.SimpleDateFormat;
43
44 public class FileURLConnection extends URLConnection {
45
46 static String CONTENT_LENGTH = "content-length";
47 static String CONTENT_TYPE = "content-type";
48 static String TEXT_PLAIN = "text/plain";
49 static String LAST_MODIFIED = "last-modified";
50
51 String contentType;
52 InputStream is;
53
54 File file;
55 String filename;
56 boolean isDirectory = false;
57 boolean exists = false;
58 List<String> files;
59
60 long length = -1;
61 long lastModified = 0;
62
63 protected FileURLConnection(URL u, File file) {
203 // Put it into a (default) locale-specific byte-stream.
204 is = new ByteArrayInputStream(sb.toString().getBytes());
205 } else {
206 throw new FileNotFoundException(filename);
207 }
208 }
209 return is;
210 }
211
212 Permission permission;
213
214 /* since getOutputStream isn't supported, only read permission is
215 * relevant
216 */
217 public Permission getPermission() throws IOException {
218 if (permission == null) {
219 String decodedPath = ParseUtil.decode(url.getPath());
220 if (File.separatorChar == '/') {
221 permission = new FilePermission(decodedPath, "read");
222 } else {
223 // decode could return /c:/x/y/z.
224 if (decodedPath.length() > 2 && decodedPath.charAt(0) == '/'
225 && decodedPath.charAt(2) == ':') {
226 decodedPath = decodedPath.substring(1);
227 }
228 permission = new FilePermission(
229 decodedPath.replace('/', File.separatorChar), "read");
230 }
231 }
232 return permission;
233 }
234 }
|