[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: fixes for file:// connections to directories
Kaffe CVS
cvs-commits at kaffe.org
Wed Mar 2 15:24:43 PST 2005
PatchSet 5492
Date: 2005/03/02 23:02:51
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Resynced with GNU Classpath: fixes for file:// connections to directories
2005-03-02 Dalibor Topic <robilad at kaffe.org>
Resynced with GNU Classpath.
2005-02-27 Chris Burdess <dog at gnu.org>
* gnu/java/net/protocol/file/Connection.java: Return correct content
length for directory listing.
* java/net/URLClassLoader.java: Correction for URLClassLoader, bug
#11285: return valid URLs for directories.
Members:
ChangeLog:1.3666->1.3667
libraries/javalib/gnu/java/net/protocol/file/Connection.java:1.11->1.12
libraries/javalib/java/net/URLClassLoader.java:1.23->1.24
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3666 kaffe/ChangeLog:1.3667
--- kaffe/ChangeLog:1.3666 Wed Mar 2 22:56:10 2005
+++ kaffe/ChangeLog Wed Mar 2 23:02:51 2005
@@ -2,6 +2,17 @@
Resynced with GNU Classpath.
+ 2005-02-27 Chris Burdess <dog at gnu.org>
+
+ * gnu/java/net/protocol/file/Connection.java: Return correct content
+ length for directory listing.
+ * java/net/URLClassLoader.java: Correction for URLClassLoader, bug
+ #11285: return valid URLs for directories.
+
+2005-03-02 Dalibor Topic <robilad at kaffe.org>
+
+ Resynced with GNU Classpath.
+
2005-02-27 Roman Kennke <roman at ontographics.com>
* javax/swing/JList.java
Index: kaffe/libraries/javalib/gnu/java/net/protocol/file/Connection.java
diff -u kaffe/libraries/javalib/gnu/java/net/protocol/file/Connection.java:1.11 kaffe/libraries/javalib/gnu/java/net/protocol/file/Connection.java:1.12
--- kaffe/libraries/javalib/gnu/java/net/protocol/file/Connection.java:1.11 Mon Feb 14 20:49:28 2005
+++ kaffe/libraries/javalib/gnu/java/net/protocol/file/Connection.java Wed Mar 2 23:02:57 2005
@@ -42,6 +42,7 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -49,6 +50,8 @@
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
@@ -92,6 +95,11 @@
private File file;
/**
+ * If a directory, contains a list of files in the directory.
+ */
+ private byte[] directoryListing;
+
+ /**
* InputStream if we are reading from the file
*/
private InputStream inputStream;
@@ -140,13 +148,7 @@
{
if (doInput)
{
- StringBuffer sb = new StringBuffer();
- String[] files = file.list();
-
- for (int index = 0; index < files.length; ++index)
- sb.append(files[index]).append(StaticData.lineSeparator);
-
- inputStream = new ByteArrayInputStream(sb.toString().getBytes());
+ inputStream = new ByteArrayInputStream(getDirectoryListing());
}
if (doOutput)
@@ -156,6 +158,32 @@
connected = true;
}
+
+ /**
+ * Populates the <code>directoryListing</code> field with a byte array
+ * containing a representation of the directory listing.
+ */
+ byte[] getDirectoryListing()
+ throws IOException
+ {
+ if (directoryListing == null)
+ {
+ ByteArrayOutputStream sink = new ByteArrayOutputStream();
+ // NB uses default character encoding for this system
+ Writer writer = new OutputStreamWriter(sink);
+
+ String[] files = file.list();
+
+ for (int i = 0; i < files.length; i++)
+ {
+ writer.write(files[i]);
+ writer.write(StaticData.lineSeparator);
+ }
+
+ directoryListing = sink.toByteArray();
+ }
+ return directoryListing;
+ }
/**
* Opens the file for reading and returns a stream for it.
@@ -229,7 +257,13 @@
if (field.equals("content-type"))
return guessContentTypeFromName(file.getName());
else if (field.equals("content-length"))
- return Long.toString(file.length());
+ {
+ if (file.isDirectory())
+ {
+ return Integer.toString(getContentLength());
+ }
+ return Long.toString(file.length());
+ }
else if (field.equals("last-modified"))
{
synchronized (StaticData.dateFormat)
@@ -258,6 +292,10 @@
if (!connected)
connect();
+ if (file.isDirectory())
+ {
+ return getDirectoryListing().length;
+ }
return (int) file.length();
}
catch (IOException e)
Index: kaffe/libraries/javalib/java/net/URLClassLoader.java
diff -u kaffe/libraries/javalib/java/net/URLClassLoader.java:1.23 kaffe/libraries/javalib/java/net/URLClassLoader.java:1.24
--- kaffe/libraries/javalib/java/net/URLClassLoader.java:1.23 Wed Feb 16 03:43:37 2005
+++ kaffe/libraries/javalib/java/net/URLClassLoader.java Wed Mar 2 23:02:58 2005
@@ -536,7 +536,7 @@
Resource getResource(String name)
{
File file = new File(dir, name);
- if (file.exists() && ! file.isDirectory())
+ if (file.exists())
return new FileResource(this, name, file);
return null;
}
@@ -554,11 +554,36 @@
InputStream getInputStream() throws IOException
{
+ // Delegate to the URL content handler mechanism to retrieve an
+ // HTML representation of the directory listing if a directory
+ if (file.isDirectory())
+ {
+ URL url = getURL();
+ return url.openStream();
+ }
+ // Otherwise simply return a FileInputStream
return new FileInputStream(file);
}
public int getLength()
{
+ // Delegate to the URL content handler mechanism to retrieve the
+ // length of the HTML representation of the directory listing if
+ // a directory, or -1 if an exception occurs opening the directory.
+ if (file.isDirectory())
+ {
+ URL url = getURL();
+ try
+ {
+ URLConnection connection = url.openConnection();
+ return connection.getContentLength();
+ }
+ catch (IOException e)
+ {
+ return -1;
+ }
+ }
+ // Otherwise simply return the file length
return (int) file.length();
}
More information about the kaffe
mailing list