1 package org
.de
.metux
.util
;
5 import java
.io
.InputStreamReader
;
6 import java
.io
.FileReader
;
7 import java
.io
.FileNotFoundException
;
8 import java
.io
.IOException
;
10 import java
.net
.URLConnection
;
11 import java
.net
.MalformedURLException
;
15 abstract class Instance
17 public abstract String
toString();
18 abstract URL
toURL() throws MalformedURLException
;
19 abstract Reader
getReader() throws FileNotFoundException
, IOException
;
21 class Instance_Name
extends Instance
24 Instance_Name(String n
)
28 public String
toString()
32 URL
toURL() throws MalformedURLException
36 Reader
getReader() throws FileNotFoundException
, IOException
38 return new FileReader(new File(name
));
41 class Instance_File
extends Instance
48 public String
toString()
50 return file
.toString();
52 URL
toURL() throws MalformedURLException
56 Reader
getReader() throws FileNotFoundException
, IOException
58 return new FileReader(file
);
61 class Instance_URL
extends Instance
68 public String
toString()
70 return url
.toString();
72 URL
toURL() throws MalformedURLException
76 Reader
getReader() throws FileNotFoundException
, IOException
78 URLConnection conn
= url
.openConnection();
79 conn
.setDoOutput(true);
80 return new InputStreamReader(conn
.getInputStream());
84 private Instance instance
;
86 public Filename(String s
)
88 /* try whether it's a valid URL */
91 instance
= new Instance_URL(new URL(s
));
93 catch (MalformedURLException e
)
95 instance
= new Instance_Name(s
);
99 public Filename(File f
)
101 instance
= new Instance_File(f
);
104 public Filename(URL u
)
106 instance
= new Instance_URL(u
);
110 throws MalformedURLException
112 return instance
.toURL();
115 public String
toString()
117 return instance
.toString();
120 public Reader
getReader()
121 throws FileNotFoundException
, IOException
123 return instance
.getReader();