This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: gnu.java.net.protocol.file.Connection
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Fri, 10 Sep 2004 09:26:43 +0200
- Subject: Patch: gnu.java.net.protocol.file.Connection
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to merge with GNU classpath again
and to add the ability to read directory contents easily.
Michael
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.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBQVc8WSOgCCdjSDsRAopLAKCHmhQX/SVAEx3qoeky71C4Q5Ig/gCfenOr
VObpD6Gn3DoXK1u9lpAGhHI=
=1Ds9
-----END PGP SIGNATURE-----
Index: gnu/java/net/protocol/file/Connection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/net/protocol/file/Connection.java,v
retrieving revision 1.7
diff -u -r1.7 Connection.java
--- gnu/java/net/protocol/file/Connection.java 23 Jul 2004 01:21:39 -0000 1.7
+++ gnu/java/net/protocol/file/Connection.java 10 Sep 2004 07:19:43 -0000
@@ -37,8 +37,11 @@
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.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 @@
= 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 @@
// 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 @@
/**
* Get the length of content.
+ *
* @return the length of the content.
*/
public int getContentLength()
@@ -212,7 +246,7 @@
{
if (!connected)
connect();
-
+
return file.lastModified();
}
catch (IOException e)
@@ -220,7 +254,7 @@
return -1;
}
}
-
+
/**
* This method returns a <code>Permission</code> object representing the
* permissions required to access this URL. This method returns a