diff options
author | Michael Koch <konqueror@gmx.de> | 2004-09-09 14:37:06 +0000 |
---|---|---|
committer | Michael Koch <konqueror@gmx.de> | 2004-09-09 14:37:06 +0000 |
commit | 9ac2487e1ece42bcc65d6eec8b5255a5ce9e2c8a (patch) | |
tree | 1cb6bc3ed80b3d2a93b21389ae6f4c4cf160da89 | |
parent | 894fd126d604f104f083c05fcd72999e616e1651 (diff) | |
download | classpath-9ac2487e1ece42bcc65d6eec8b5255a5ce9e2c8a.tar.gz |
2004-09-09 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/file/Connection.java
(connect): Handle file is a directory case.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | gnu/java/net/protocol/file/Connection.java | 42 |
2 files changed, 43 insertions, 4 deletions
@@ -1,3 +1,8 @@ +2004-09-09 Michael Koch <konqueror@gmx.de> + + * gnu/java/net/protocol/file/Connection.java + (connect): Handle file is a directory case. + 2004-09-08 Sven de Marothy <sven@physto.se> Patch from David Gilbert <david.gilbert@object-refinery.com>: diff --git a/gnu/java/net/protocol/file/Connection.java b/gnu/java/net/protocol/file/Connection.java index 0dc223cf0..89dd63a49 100644 --- a/gnu/java/net/protocol/file/Connection.java +++ b/gnu/java/net/protocol/file/Connection.java @@ -37,6 +37,8 @@ exception statement from your version. */ package gnu.java.net.protocol.file; +import gnu.java.security.action.GetPropertyAction; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; @@ -46,10 +48,12 @@ import java.io.FilePermission; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; +import java.io.StringBufferInputStream; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.security.Permission; +import java.security.AccessController; import java.util.AbstractSet; import java.util.Iterator; import java.util.Set; @@ -70,6 +74,15 @@ public class Connection extends URLConnection */ private static final String DEFAULT_PERMISSION = "read"; + private static final String lineSeparator; + + static + { + GetPropertyAction getProperty = new GetPropertyAction("line.separator"); + lineSeparator = (String) AccessController.doPrivileged(getProperty); + + } + /** * This is a File object for this connection */ @@ -111,11 +124,32 @@ public class Connection extends URLConnection // If not connected, then file needs to be openned. file = new File (getURL().getFile()); - if (doInput) - inputStream = new BufferedInputStream(new FileInputStream(file)); + + if (! file.isDirectory()) + { + if (doInput) + inputStream = new BufferedInputStream(new FileInputStream(file)); - if (doOutput) - outputStream = new BufferedOutputStream(new FileOutputStream(file)); + if (doOutput) + outputStream = new BufferedOutputStream(new FileOutputStream(file)); + } + else + { + if (doInput) + { + StringBuffer sb = new StringBuffer(); + String[] files = file.list(); + + for (int index = 0; index < files.length; ++index) + sb.append(files[index]).append(lineSeparator); + + inputStream = new StringBufferInputStream(sb.toString()); + } + + if (doOutput) + throw new ProtocolException + ("file: protocol does not support output on directories"); + } connected = true; } |