diff options
author | Michael Koch <konqueror@gmx.de> | 2004-09-10 07:20:09 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2004-09-10 07:20:09 +0000 |
commit | 5123971af819e3313bfb1b2716e9b20761d1294c (patch) | |
tree | 2dc2c92bfb5a29c5540665d078ae4133504aab06 /libjava/gnu | |
parent | 456d47b390e757c7eaed61f69a88f836d8896edc (diff) | |
download | gcc-5123971af819e3313bfb1b2716e9b20761d1294c.zip gcc-5123971af819e3313bfb1b2716e9b20761d1294c.tar.gz gcc-5123971af819e3313bfb1b2716e9b20761d1294c.tar.bz2 |
2004-09-10 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/file/Connection.java
(lineSeparator): Made non-final.
(static): Removed.
(connect): Initialize lineSeparator lazily. Use ByteArrayInputStream
instead of StringBufferInputStream.
2004-09-10 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/file/Connection.java
(connect): Handle file is a directory case.
From-SVN: r87279
Diffstat (limited to 'libjava/gnu')
-rw-r--r-- | libjava/gnu/java/net/protocol/file/Connection.java | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/libjava/gnu/java/net/protocol/file/Connection.java b/libjava/gnu/java/net/protocol/file/Connection.java index 4da6e88..3927130 100644 --- a/libjava/gnu/java/net/protocol/file/Connection.java +++ b/libjava/gnu/java/net/protocol/file/Connection.java @@ -37,8 +37,11 @@ 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.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -50,6 +53,7 @@ import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.security.Permission; +import java.security.AccessController; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -71,6 +75,8 @@ public class Connection extends URLConnection = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", new Locale ("En", "Us", "Unix")); + private static String lineSeparator; + /** * This is a File object for this connection */ @@ -105,11 +111,38 @@ 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) + { + if (lineSeparator == null) + { + GetPropertyAction getProperty = new GetPropertyAction("line.separator"); + lineSeparator = (String) AccessController.doPrivileged(getProperty); + } + + StringBuffer sb = new StringBuffer(); + String[] files = file.list(); + + for (int index = 0; index < files.length; ++index) + sb.append(files[index]).append(lineSeparator); + + inputStream = new ByteArrayInputStream(sb.toString().getBytes()); + } + + if (doOutput) + throw new ProtocolException + ("file: protocol does not support output on directories"); + } connected = true; } @@ -184,6 +217,7 @@ public class Connection extends URLConnection /** * Get the length of content. + * * @return the length of the content. */ public int getContentLength() @@ -212,7 +246,7 @@ public class Connection extends URLConnection { if (!connected) connect(); - + return file.lastModified(); } catch (IOException e) @@ -220,7 +254,7 @@ public class Connection extends URLConnection return -1; } } - + /** * This method returns a <code>Permission</code> object representing the * permissions required to access this URL. This method returns a |