37 |
|
|
38 |
package gnu.java.net.protocol.file; |
package gnu.java.net.protocol.file; |
39 |
|
|
40 |
|
import gnu.java.security.action.GetPropertyAction; |
41 |
|
|
42 |
import java.io.BufferedInputStream; |
import java.io.BufferedInputStream; |
43 |
import java.io.BufferedOutputStream; |
import java.io.BufferedOutputStream; |
44 |
import java.io.File; |
import java.io.File; |
48 |
import java.io.InputStream; |
import java.io.InputStream; |
49 |
import java.io.IOException; |
import java.io.IOException; |
50 |
import java.io.OutputStream; |
import java.io.OutputStream; |
51 |
|
import java.io.StringBufferInputStream; |
52 |
import java.net.ProtocolException; |
import java.net.ProtocolException; |
53 |
import java.net.URL; |
import java.net.URL; |
54 |
import java.net.URLConnection; |
import java.net.URLConnection; |
55 |
import java.security.Permission; |
import java.security.Permission; |
56 |
|
import java.security.AccessController; |
57 |
import java.util.AbstractSet; |
import java.util.AbstractSet; |
58 |
import java.util.Iterator; |
import java.util.Iterator; |
59 |
import java.util.Set; |
import java.util.Set; |
74 |
*/ |
*/ |
75 |
private static final String DEFAULT_PERMISSION = "read"; |
private static final String DEFAULT_PERMISSION = "read"; |
76 |
|
|
77 |
|
private static final String lineSeparator; |
78 |
|
|
79 |
|
static |
80 |
|
{ |
81 |
|
GetPropertyAction getProperty = new GetPropertyAction("line.separator"); |
82 |
|
lineSeparator = (String) AccessController.doPrivileged(getProperty); |
83 |
|
|
84 |
|
} |
85 |
|
|
86 |
/** |
/** |
87 |
* This is a File object for this connection |
* This is a File object for this connection |
88 |
*/ |
*/ |
124 |
|
|
125 |
// If not connected, then file needs to be openned. |
// If not connected, then file needs to be openned. |
126 |
file = new File (getURL().getFile()); |
file = new File (getURL().getFile()); |
127 |
if (doInput) |
|
128 |
inputStream = new BufferedInputStream(new FileInputStream(file)); |
if (! file.isDirectory()) |
129 |
|
{ |
130 |
|
if (doInput) |
131 |
|
inputStream = new BufferedInputStream(new FileInputStream(file)); |
132 |
|
|
133 |
if (doOutput) |
if (doOutput) |
134 |
outputStream = new BufferedOutputStream(new FileOutputStream(file)); |
outputStream = new BufferedOutputStream(new FileOutputStream(file)); |
135 |
|
} |
136 |
|
else |
137 |
|
{ |
138 |
|
if (doInput) |
139 |
|
{ |
140 |
|
StringBuffer sb = new StringBuffer(); |
141 |
|
String[] files = file.list(); |
142 |
|
|
143 |
|
for (int index = 0; index < files.length; ++index) |
144 |
|
sb.append(files[index]).append(lineSeparator); |
145 |
|
|
146 |
|
inputStream = new StringBufferInputStream(sb.toString()); |
147 |
|
} |
148 |
|
|
149 |
|
if (doOutput) |
150 |
|
throw new ProtocolException |
151 |
|
("file: protocol does not support output on directories"); |
152 |
|
} |
153 |
|
|
154 |
connected = true; |
connected = true; |
155 |
} |
} |